[백준 브론즈 V] 11021번: A+B - 7

DONI·2021년 8월 7일
0

Baekjoon Online Judge

목록 보기
23/31
post-thumbnail

문제

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


입력

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

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


출력

각 테스트 케이스마다 "Case #x: "를 출력한 다음, A+B를 출력한다. 테스트 케이스 번호는 1부터 시작한다.


예제 입력 1

5
1 1
2 3
3 4
9 8
5 2

예제 출력 1

Case #1: 2
Case #2: 5
Case #3: 7
Case #4: 17
Case #5: 7


소스코드

  • Java 첫 번째 방법 : for 문
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println("Case #" + (i + 1) + ": " + (a + b));
		} sc.close();
	}
}
  • Java 두 번째 방법 : while 문
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();		
		int i = 0;
		while (i < t) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println("Case #" + (i + 1) + ": " + (a + b));
			i++;
		} sc.close();
	}
}
  • Java 세 번째 방법 : do-while 문
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int i = 0;
		do {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println("Case #" + (i + 1) + ": " + (a + b));
			i++;
		} while (i < t);
		sc.close();
	}
}

[바로가기] 11021번: A+B - 7

profile
틀린 내용이 있다면 댓글 또는 이메일로 알려주세요 ❤ꔛ❜

0개의 댓글