split 사용
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int num = Integer.parseInt(br.readLine());
for (int i = 0; i < num; i++) {
String[] s = br.readLine().split(" ");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
bw.write(a + b + "\n");
}
bw.flush();
}
}
StringTokenizer 사용
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int num = Integer.parseInt(br.readLine());
for (int i = 0; i < num; i++) {
StringTokenizer st=new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
bw.write(a + b + "\n");
}
bw.flush();
}
}
'💡 Algorithm > 백준' 카테고리의 다른 글
[JAVA ] 백준 #1157- 단어 공부 (0) | 2020.08.20 |
---|---|
[JAVA ] 백준 #2839- 설탕 배달 (0) | 2020.08.20 |
[JAVA] 백준 #2741 - N 찍기 (Scanner,BufferedReader,BufferedWriter) (0) | 2020.06.24 |
[JAVA] 백준 #2884 - 알람 시계 (0) | 2020.06.16 |
[C] 백준 #10430 - 나머지 (0) | 2020.06.15 |
[C] 백준 #2588 - 곱셈 (0) | 2020.06.15 |