포스트

[Java] Baekjun 10951 - A+B - 4

We have summarized how to handle the A+B problem with an undetermined number of inputs using Java's hasNext().

한국어 원문은 여기에서 볼 수 있습니다.
[Java] Baekjun 10951 - A+B - 4

BaekJoon 10951

Solution

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);
        }
    }
}

EOF in class Scanner

  • Using hasNext() method
  • Returns true if there is an entered token, otherwise returns false.