import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class BJ15552{
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 n= Integer.parseInt(br.readLine());
for(int i=0; i<n;i++){
String s =br.readLine();
int a =Integer.parseInt(s.split(" ")[0]);
int b =Integer.parseInt(s.split(" ")[1]);
bw.write(a+b+"\n");
}
br.close();
// bw.flush();
bw.close();
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class BJ15552{
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 n= Integer.parseInt(br.readLine());
StringTokenizer st;
for(int i=0; i<n;i++){
st =new StringTokenizer(br.readLine()," ");
int a =Integer.parseInt(st.nextToken());
int b =Integer.parseInt(st.nextToken());
bw.write(a+b+"\n"); //버퍼에 값이 쌓인다.
}
br.close();
//bw.flush();
bw.close(); //출력!
}
}
- 스트림을 사용하고 있는데 버퍼를 비워야 할 때 flush() 사용하면 될 것 같다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BJ15552{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
String s=br.readLine();
int a=Integer.parseInt(s.split(" ")[0]);
int b=Integer.parseInt(s.split(" ")[1]);
sb.append(a+b+"\n");
}
br.close();
System.out.println(sb);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BJ15552{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine()," ");
sb.append(Integer.parseInt(st.nextToken()) + Integer.parseInt(st.nextToken())).append('\n');
}
br.close();
System.out.println(sb);
}
}
Reference: