leehyeon-dv 님의 블로그
(반복문) A+B (4) 본문
📌 문제
🐍파이썬
import sys
addResult = []
while True:
try:
A, B = map(int, sys.stdin.readline().split())
addResult.append(A + B)
except:
break
for i in range(len(addResult)):
print(addResult[i])
🧩자바
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
List<Integer> addResult = new ArrayList<>();
while (true) {
try {
String input = br.readLine();
if (input == null || input.isEmpty()) {
break;
}
String[] numbers = input.split(" ");
int A = Integer.parseInt(numbers[0]);
int B = Integer.parseInt(numbers[1]);
addResult.add(A + B);
} catch (Exception e) {
break;
}
}
for (int i=0; i<addResult.size(); i++){
bw.write(addResult.get(i) + "\n");
}
}
}
'코딩테스트 > 백준' 카테고리의 다른 글
(반복문) A+B (5) (0) | 2024.12.31 |
---|---|
(반복문)별 찍기(2) (1) | 2024.12.31 |
(반복문) 별찍기 (1) (1) | 2024.12.31 |
(반복문)A+B(8) (0) | 2024.12.31 |
(반복문)빠르게 A+B(7) (0) | 2024.12.31 |