JAVA
[JAVA][백준] 2562_최댓값
saemsaem
2024. 4. 15. 19:23
import java.util.Scanner;
public class Zmax_2562 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int[] arrNum = new int[9];
int max = 1;
int cnt = 0;
for (int i = 0; i < 9; i++) {
arrNum[i] = sc.nextInt();
}
for (int i = 0; i < 9; i++) {
if (arrNum[i] > max) {
max = arrNum[i];
cnt = i+1;
}
}
System.out.println(max +"\n"+ cnt);
}
}
배열 선언 시 : 9개의 칸을 가진 배열을 선언하고 싶다면
int [ ] num = new int [ 9 ];
배열의 번호 (0~8)이 아닌, 칸의 개수로 선언해야 한다.