[Java] 백준 10951번 - A+B - 4
Java Scanner hasNext() 메서드 활용 입력 종료 판단, EOF(End of File) 처리 기법
For the English version of this post, see here.
[Java] 백준 10951번 - A+B - 4
풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int a = sc.nextInt();
int b = sc.nextInt();
System.out.printf("%d\n", a+b);
}
}
}
Scanner 클래스에서의 EOF
hasNext()메소드 사용하기- 입력된 토큰이 있으면 true 반환, 그렇지 않을 경우 false 반환
댓글
궁금한 점, 피드백, 오류 제보를 남겨 주세요.