[JAVA | 백준 2562] 최댓값
· 테크· Java
Java
백준 2562번 www.acmicpc.net/problem/2562
풀이
Collections.max() 메서드를 이용했다. Collection으로 할 때 배열의 범위를 정하지 않아도 되서 이 문제를 풀 때 효율적이었던 것 같다. 자료를 입력받을 때는 .add() 메서드를, 자료를 가져올 때는 .get() 메서드를 활용한다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import java.util.*;
public class Array_2562 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> listArr = new ArrayList<>();
int no = 0;
for (int i=0; i<9; i++) {
listArr.add(sc.nextInt());
}
int max = Collections.max(listArr);
for (int i=0; i<9; i++) {
if(listArr.get(i)==max) {
no=i;
break;
}
}
System.out.println(max);
System.out.println(no+1);
sc.close();
}
}
|
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