[Java | 백준 2750번] 수 정렬하기
· 테크· Java
Java
백준 2750번 www.acmicpc.net/problem/2750
풀이
Collection 중 Arraylist.sort() 메서드를 이용해서 풀이했다. 메서드를 통해 오름차순 정렬이 가능하다. 값은 Integer 타입으로 받아와야 음수 값이 들어와도 바르게 정렬된다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import java.util.*;
public class sort_2750 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
sc.nextLine();
List<Integer> intList = new ArrayList<>();
for (int i=0; i<a; i++) {
intList.add(Integer.parseInt(sc.nextLine()));
}
Collections.sort(intList);
for (int i=0; i<a; i++) {
System.out.println(intList.get(i));
}
}
}
|
cs |
Comments
No comments yet. Be the first!
319 posts in 테크
- 368Supabase 프로젝트 복사하기 (Restore to a New Project)NEW
- 341Migrating from Permanent Access Tokens to Token Exchange — Why Order Matters
- 326Startup & Product Glossary: Terms Every Solo Founder Should Know
- 325Context Management — How I Do It Now
- 324Claude Code Routines vs Cowork Schedule — What's the Difference?
1–5 / 319