본문 바로가기
Algorithm/Beakjoon

[Java] baekjoon 11022 : A+B - 8 / for문

by Amy97 2021. 8. 24.
728x90

문제 


https://www.acmicpc.net/problem/11022

 

11022번: A+B - 8

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

www.acmicpc.net

해결 


System.out.printf(format, arguments)

%s : String 형식
%d : integer 형식
%f : float 형식
%t : date, time 형식
%o : 8진수 integer 형식
%x : 16진수 integer 형식
%b : boolean 형식
%e : 지수 형식

구현 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        
        int t = sc.nextInt();
        int [] a = new int [t];
        int [] b = new int [t];
        
        for (int i = 0; i < t; i ++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            System.out.printf("Case #%d: %d + %d = %d \n", i + 1, a[i], b[i], a[i] + b[i]);
        }
 
    }
}
cs

결과 


728x90

댓글