본문 바로가기
Etc/Coding Test

[JAVA] 백준 10951번: A+B - 4 / hasNextInt() / 입력이 있을 때만 반복

by 달의 조각 2021. 8. 1.

 

 

while문에 조건을 true로 놓을 시 런타임 에러 발생, 입력이 있을 때만 반복이 되도록 조건을 준다.

hasNextInt()

 

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        while(sc.hasNextInt())
        {
            int a = sc.nextInt();
            int b = sc.nextInt();
        	
        	System.out.println(a+b);
        }
    }
}

댓글