[백준java] while - 10951 / A + B - 4

2021. 10. 20. 17:00

이거 그냥 하면 되는줄 알았더니 모르는 무언가가 필요했던 문제..( NoSuchElementException이 떴었다. )

 

import java.util.Scanner;

// A+B - 4
public class Main {
    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        
        while(scanner.hasNextInt()) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            
            System.out.println(a+b);           
        }
        scanner.close();
    }
}

 

여기서 써주는 hasNextInt()는 (일단 정수형으로 보면) int일 경우 true값을 반환하고 아닐 경우 false를 반환하는 함수이다. 

 

새로운거 알아가기..

BELATED ARTICLES

more