본문으로 건너뛰기
이준석 개발 블로그
돌아가기

A+B_3

1분 분량이 글 고치기
목차 · 6

문제

입력

출력

각 테스트 케이스마다 A+B를 출력한다.

예제 입력 1

5
1 1
2 3
3 4
9 8
5 2

예제 출력 1

2
5
7
17
7

해결방법

조건에 따라 식을 작성하면 된다.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
//    두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

        Scanner sc = new Scanner(System.in);
        int testCase = sc.nextInt();
        int[] a = new int[testCase];
        int[] b = new int[testCase];
        int[] result = new int[testCase];

        for (int i = 0; i < testCase; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            result[i] = a[i] + b[i];
        }
        for (int i = 0; i<testCase; i++){
            System.out.println(result[i]);
        }

//    첫째 줄에 테스트 케이스의 개수 T가 주어진다.
//     각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 < A, B < 10)
    }
}

이 글 고치기
이 글 공유하기:

이전 글
N 찍기
다음 글
Decode