๋ฐ์ํ
3. for๋ฌธ - A+B - 8
๋ฌธ์ ) ๋ ์ ์ A์ B๋ฅผ ์ ๋ ฅ๋ฐ์ ๋ค์, A+B๋ฅผ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ ๋ ฅ | ์ถ๋ ฅ |
5 1 1 2 3 3 4 9 8 5 2 |
Case #1: 1 + 1 = 2 Case #2: 2 + 3 = 5 Case #3: 3 + 4 = 7 Case #4: 9 + 8 = 17 Case #5: 5 + 2 = 7 |
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i <= n; i++) { // i๋ 1์ด๊ณ i๊ฐ n๊ณผ ํฌ๊ฑฐ๋ ๊ฐ์๋๊น์ง i๊ฐ ์ถ๋ ฅ ํ 1์ฉ ์ฆ๊ฐ
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println("Case #" + i + ": " + a + " + " + b + " = " + (a + b));
}
}
}
๋ฐ์ํ
'Algorithm > ๋ฐฑ์ค ์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค ์๊ณ ๋ฆฌ์ฆ] 2439๋ฒ - ๋ณ ์ฐ๊ธฐ - 2 (0) | 2021.01.31 |
---|---|
[๋ฐฑ์ค ์๊ณ ๋ฆฌ์ฆ] 2438๋ฒ - ๋ณ ์ฐ๊ธฐ - 1 (0) | 2021.01.31 |
[๋ฐฑ์ค ์๊ณ ๋ฆฌ์ฆ] 11021๋ฒ - A+B - 7 (0) | 2021.01.31 |
[๋ฐฑ์ค ์๊ณ ๋ฆฌ์ฆ] 2742๋ฒ - ๊ธฐ์ฐ N (0) | 2021.01.31 |
[๋ฐฑ์ค ์๊ณ ๋ฆฌ์ฆ] 2741๋ฒ - N ์ฐ๊ธฐ (0) | 2021.01.31 |
๋๊ธ