알고리즘/백준

백준 10951 A+B-4

고구마와 감자 2022. 3. 2. 22:57

https://www.acmicpc.net/problem/10951

 

10951번: A+B - 4

두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

 

BufferedReader와 Scanner를 쓸 때 약간 다를 것이다.

여기서는 while문 반복 체크할때 할당도 동시에 해주는 점이 주의할 점이다. 

public class Boj10951 {
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st;
        String str ="";
        while((str = br.readLine()) != null) {
            st = new StringTokenizer(str);
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            System.out.println(a+b);
        }
    }
}