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++;
}
}
}
0