A+B - 8

hovi·2023년 5월 30일
0

코딩테스트 백준

목록 보기
28/59
시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초256 MB1559161060579434768.748%

문제

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

입력

첫째 줄에 테스트 케이스의 개수 T가 주어진다.

각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 < A, B < 10)

출력

각 테스트 케이스마다 "Case #x: A + B = C" 형식으로 출력한다. x는 테스트 케이스 번호이고 1부터 시작하며, C는 A+B이다.

예제 입력 1

5
1 1
2 3
3 4
9 8
5 2

예제 출력 1

Case #1: 1 + 1 = 2
Case #2: 2 + 3 = 5
Case #3: 3 + 4 = 7
Case #4: 9 + 8 = 17
Case #5: 5 + 2 = 7

풀이

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a;
        int b;
        int num = 0;
        ArrayList<Integer> arr = new ArrayList<>();
        ArrayList<Integer> anum = new ArrayList<>();
        ArrayList<Integer> bnum = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            a = sc.nextInt();
            b = sc.nextInt();
            arr.add(a+b);
            anum.add((a));
            bnum.add((b));
        }
        for (int i = 0; i < n; i++) {
            num++;
            System.out.println("Case #" +num +": "+anum.get(i)+" + "+bnum.get(i)+" = "+arr.get(i));
        }
    }
}
profile
풀스택 예비 개발자

0개의 댓글