전체 글849 11 컬렉션 프레임웍(4) Comparator와 Comparable 이전 예제에서 Arrays.sort()를 호출만 하면 컴퓨터가 알아서 배열을 정렬하는 것처럼 보이지만, 사실 Character클래스의 Cmpatable의 구현에 의해 정렬되었던 것이다. Comparator와 Comparable은 모두 인터페이스로 컬렉션을 정렬하는데 필요한 메서드를 정의하고 있으며, Comparable을 구현하고 있는 클래스들은 같은 타입의 인스턴스 끼리 서로 비교할 수 있는 클래스들, 주로 Integer와 같은 wrapper클래스와 String, Date, File과 같은 것들이며 기본적으로 오름차순, 즉 작은 갑셍서부터 큰 값의 순으로 정렬되도록 구현되어 있다. 그래서 Comparable을 구현한 클래스는 정렬이 가능하다는 것을 의미한다. Co.. 2021. 7. 8. 백준 4344 import java.util.Scanner; public class Main4344 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int C = sc.nextInt(); String[] ratio = new String[C]; double[] aver = new double[C]; int sum = 0; int cnt = 0; for (int i = 0; i < C; i++) { int N = sc.nextInt(); int[] score = new int[N]; for (int j = 0; j < N; j++) { score[j] = sc.nextInt(); sum += score[j]; if (j == .. 2021. 7. 8. 백준 1546 import java.util.Scanner; public class Main1546 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int N = s.nextInt(); double[] score = new double[N]; double sum = 0; double aver = 0; int highscore = 0; for (int i = 0; i < N; i++) { score[i] = (double) s.nextInt(); if (highscore < score[i]) { highscore = (int) score[i]; } } for (int i = 0; i < N; i++) { score[i] = (d.. 2021. 7. 8. 백준 8958 import java.util.Scanner; public class Main8958 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int T = s.nextInt(); String[] result = new String[T]; int[] score = new int[T]; s.nextLine(); for (int i = 0; i < T; i++) result[i] = s.nextLine(); for (int i = 0; i < T; i++) { int continuesScore = 0; for (int j = 0; j < result[i].length(); j++) { if (result[i].charAt(j.. 2021. 7. 8. 그래프 개념 보호되어 있는 글 입니다. 2021. 7. 7. 이진 탐색(Binary Search) 보호되어 있는 글 입니다. 2021. 7. 7. 이전 1 ··· 118 119 120 121 122 123 124 ··· 142 다음