์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step4] 10951 : A+B - 4 (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 7. 22:15

www.acmicpc.net/problem/10951

 

10951๋ฒˆ: A+B - 4

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

www.acmicpc.net


๋ฌธ์ œ

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

 

์ž…๋ ฅ

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.

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

 

์ถœ๋ ฅ

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

 

์˜ˆ์ œ ์ž…๋ ฅ

1 1

2 3

3 4

9 8

5 2

 

์˜ˆ์ œ ์ถœ๋ ฅ

2

5

7

17

7


ํ’€์ด

1. while๋ฌธ์œผ๋กœ ๋ฌดํ•œ๋ฃจํ”„๋ฅผ ๋งŒ๋“ค์–ด a์™€b๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

2. int๊ฐ’์ด ์ž…๋ ฅ๋  ๋•Œ๋งŒ ๋ฃจํ”„๊ฐ€ ์‹คํ–‰๋˜๊ฒŒ ์กฐ๊ฑด์„ ์ž‘์„ฑํ•œ๋‹ค.

    => hasNextInt()๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ

 

import java.io.*;
import java.util.*;

public class B10951 {

	public static void main(String[] args) throws IOException {
		
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNextInt()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(a+b);
		}

	}

}