본문 바로가기

Algorithm/백준

[백준] 7891: Can you add this? - JAVA [자바]

 


 

문제


 

  1. 첫 번째 입력에서 몇번의 덧셈을 수행할지 수를 입력합니다.
  2. 입력된 수만큼 두 수를 더하여주는 문제입니다.

 

문제 풀이


 

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int number = sc.nextInt();
        //(1)


        for (int i = 0; i < number; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            System.out.println(x+y);
            //(2)

        }
    }
}

 

  1. 반복할 횟수를 입력합니다.
  2. (1)에서 입력한 수 만큼 반복하며 두 수를 입력한 뒤 두 수를 더하여 출력합니다.

 

결과