언어, 알고리즘 공부/백준
[백준 알고리즘] 10951번 A+B - 4(Python3, Java)
쿠몬e
2020. 2. 11. 18:10
<Python3>
import sys
try:
while True:
line = sys.stdin.readline()
a, b = line.split()
print(int(a) + int(b))
except:
exit()
입력 개수를 모르기 때문에 try except를 사용하였다.
<Java>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
while((line = br.readLine())!=null){
StringTokenizer st = new StringTokenizer(line, " ");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
System.out.println(a+b);
}
}
}
▼링크
https://www.acmicpc.net/problem/10951
10951번: A+B - 4
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
반응형