Coding Test/BaekJoon

[BaekJoon Java] A + B - 8(11022)

momong'-' 2020. 12. 20. 21:33

www.acmicpc.net/problem/11022

 

11022번: A+B - 8

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

www.acmicpc.net


  • 문제

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

  • 예제 입출력

  • 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package step.loopFor;
 
import java.util.Scanner;
/**
 * 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
 * @author imj10
 *
 */
public class ASumB8 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int caseCnt = sc.nextInt();
        
        for ( int i=0; i < caseCnt; i++ ) {
            
            int a = sc.nextInt();
            int b = sc.nextInt();
            
            System.out.println(String.format("Case #%d: %d + %d = %d", i+1, a, b, a+b));
        }
    }
}
 
cs
  • 결과


  • 추가설명

String.format  사용

1) %와 conversion
"conversion": 표현 할 데이터의 타입

s(문자열), d(정수), x(16진수), o(8진수), f(실수)

=> %s, %d, %x, %o, %f