백준

[백준/java자바]10951 Scanner클래스 에서 hasNext()

꿈꾸는야오옹 2022. 8. 23. 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.println(A+B);
			
		}
		
		
	}
}     //sc.hasNext() 가 true 혹은 false

hasNext() 는 Scanner를 통해 입력된 값이 있으면 true를 출력한다.

예를 들어 hasNextInt() 값을 출력할 때 정수가 들어오면 true, 입력이 없거나 정수 외의 값이 들어올 경우 false를 반환한다.