devWonny 2021. 9. 25. 11:01

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

첫째 줄에 A와 B가 주어진다. (0 < A, B < 10)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
        String[] a = rd.readLine().split(" ");
        int[] b = new int[a.length];
        int sum =0;
        for(int i=0; i<a.length; i++){
            b[i] = Integer.parseInt(a[i]);
            sum += b[i];
        }
        System.out.println(sum);

    }//main
}//class

 

특징

BufferedReader

readLine()

.split(" ");

Integer.parseInt(a[i])