while(true)로 하면 입력이 없어도 계속 돈다. 입력이 없으면 break 되어야 한다. 그런 의미에서 while(sc.hasNextInt()) 가 되어야 한다.
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> a = new ArrayList<>();
ArrayList<Integer> b = new ArrayList<>();
int i = 0;
while(sc.hasNextInt()) {
a.add(sc.nextInt() + sc.nextInt());
System.out.println(a.get(i));
i++;
}
}
}
'알고리즘 > 문제 풀이' 카테고리의 다른 글
JAVA Quiz 09 (0) | 2023.02.15 |
---|---|
[백준 1110 번] 더하기 사이클 (0) | 2023.02.13 |
[백준 10952번] A+B -5 (0) | 2023.02.10 |
[백준 2439번] 별 찍기 2 (0) | 2023.02.08 |
[백준 2438번] 별 찍기 (0) | 2023.02.08 |