โ์ช ์ ํจ๊ป ํ๋ฃจ์ 30๋ถ ์ด์ ์์โจ
2750
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] array = new int[N];
for(int i=0; i<N; i++) {
array[i] = sc.nextInt();
}
Arrays.sort(array);
for(int i :array) {
System.out.println(i);
}
}
}
2751
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder(); //๋ฌธ์์ด์ ๋ค๋ฃจ๋ ํด๋์ค
int N = sc.nextInt();
//list
ArrayList<Integer>list = new ArrayList<>();
for(int i=0; i < N; i++) {
list.add(sc.nextInt());
}
Collections.sort(list);
for(int value : list) {
sb.append(value).append('\n');
}
System.out.prinltn(sb);
}
}
โช StringBilder : String๊ณผ ๋ฌธ์์ด์ ๋ํ ๋ ์๋ก์ด ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๊ฒ์ด ์๋๋ผ
๊ธฐ์กด์ ๋ฐ์ดํฐ์ ๋ํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์๋๋ ๋น ๋ฅด๋ฉฐ ์๋์ ์ผ๋ก ๋ถํ๊ฐ ์ ๋ค
โช ArrayList : ์๋ฐ์ List ์ธํฐํ์ด์ค๋ฅผ ์์๋ฐ์ ์ฌ๋ฌ ํด๋์ค ์ค ํ๋
โช Collections.sort()์ Timesortํฉ๋ณ ๋ฐ ์ฝ์
์ ๋ ฌ์๊ณ ๋ฆฌ์ฆ ์ฌ์ฉ
10989
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
for(int i = 0; i<N; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(arr);
for(int i = 0; i< N; i++) {
sb.append(arr[i]).append('\n');
}
System.out.println(sb);
}
}