๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/๋ฐฑ์ค€

[๋ฐฑ์ค€/Java] 10950 A+B -3 : ์ž…๋ ฅ ์ŠคํŠธ๋ฆผ ์ค‘๋ณต์œผ๋กœ ์ธํ•œ ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ

by ๋ฝ€์งœ๊ผฌ 2025. 1. 17.
728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ฐ ์ค„์— A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (0 < A, B < 10)

5
1 1
2 3
3 4
9 8
5 2

์ถœ๋ ฅ

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค A+B๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

2
5
7
17
7

"์ž…๋ ฅ ์ŠคํŠธ๋ฆผ์„ ์ค‘๋ณต์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋œ๋‹ค."

 

์•„๋ž˜์˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ 

Scanner์™€ BufferedReader๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ–ˆ์„ ๊ฒฝ์šฐ

์ž…๋ ฅ ์ŠคํŠธ๋ฆผ ์ค‘๋ณต ์‚ฌ์šฉ์œผ๋กœ ์ธํ•œ ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ(์ถฉ๋Œ)์ด ๋ฐœ์ƒํ•œ๋‹ค

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        int[] list = new int[T];

        for (int i = 0; i < T; i++) {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer st = new StringTokenizer(br.readLine());
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());
            list[i] = A+B;
        }

        for (int i = 0; i < T; i++) {
            System.out.println(list[i]);
        }
    }
}

 

โœ๏ธ  ๋งž๋Š” ํ’€์ด

import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        int[] list = new int[T];

        for (int i = 0; i < T; i++) {
            int A = scanner.nextInt();
            int B = scanner.nextInt();
            list[i] = A+B;
        }

        for (int i = 0; i < T; i++) {
            System.out.println(list[i]);
        }
    }
}

 

์ด๋ ‡๊ฒŒ ํ•˜๋‚˜๋กœ ํ†ต์ผํ•ด์ค˜์•ผํ•œ๋‹ค.

ํ•˜๋‚˜๋งŒ์จ!

๋ญ๋“  ๊ณผํ•˜๋ฉด ์ข‹์ง€์•Š๋‹ค.

728x90
๋ฐ˜์‘ํ˜•