import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[][] arrList = new String[9][9];
String[] arr;
String str = null;
int max = 0; int row = 0; int col = 0;
for(int i = 0; i < arrList.length; i++) {
str = scan.nextLine();
arr = str.split(" ");
for(int j = 0; j < arr.length; j++) {
arrList[i][j] = arr[j];
int currentNum = Integer.parseInt(arr[j]);
if(currentNum > max) {
max = currentNum;
row = i+1; col = j+1;
}
}
}
System.out.println(max+"\n"+row+" "+col);
scan.close();
}
}
위의 코드에서 에러가 발생했다.
scanner가 아닌 BufferReader을 사용하여 해결한다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[][] arrList = new int[9][9];
int max = 0; int row = 0; int col = 0;
for(int i = 0; i < arrList.length; i++) {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for(int j = 0; j < arrList[i].length; j++) {
arrList[i][j] = Integer.parseInt(st.nextToken());
if(arrList[i][j] >= max) {
max = arrList[i][j];
row = i+1; col = j+1;
}
}
}
System.out.println(max);
System.out.println(row+" "+col);
}
}
max가 0일수도 있었다...
if문의 범위를 수정한다
'Algorithm > Baekjoon' 카테고리의 다른 글
[백준_JAVA] 9506 약수들의 합 (0) | 2024.01.27 |
---|---|
[백준_JAVA] 1193 분수찾기 (0) | 2024.01.27 |
[백준_JAVA] 10798 세로읽기 (0) | 2024.01.27 |
[백준_JAVA] 15894 수학은 체육과목 입니다 (0) | 2024.01.21 |
[백준_JAVA] 3009 네 번째 점 (0) | 2024.01.21 |