package project;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
static class Solution{
int [][] array = { {1,3} ,{2,3} ,{3,2} ,{3,1} ,{2,5} ,{2,1} };
Solution(){
}//constructor : Solution(nothing)
void sortArray(){
Arrays.sort(array, new Comparator<int []>(){
public int compare(int a[], int b[]){
if(a[0] == b[0]) return Integer.compare(a[1], b[1]);
else return Integer.compare(a[0], b[0]);
}
});
}// method : sortArray
void showArray () {
for(int i = 0; i <= array.length-1 ; i++){
for(int j = 0; j <= array[i].length-1; j++){
System.out.print(array[i][j]);
}// for : j
System.out.println();
}//for : i
}// method showArray
}//class Solution
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello goorm!");
Solution solution = new Solution();
solution.sortArray();
solution.showArray();
}
}
'Program > JAVA' 카테고리의 다른 글
폴더 삭제 : 삭제.(FileUtils.cleanDirectory()와 File.delete()) (0) | 2019.12.23 |
---|---|
split()에 관하여 (0) | 2018.11.12 |
배열 복사 : clone()과 arraycopy()의 차이 (0) | 2018.09.03 |
키벨류값을 정렬해주는 메서드. (0) | 2018.08.21 |
hasNextLine()에 관하여 (0) | 2017.07.07 |