LanQiaoTestCodes/快读演示.java

29 lines
901 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package Course_Codes;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//基于 BufferedReader 的Java快读快读演示
public class 快读演示 {
public static void main(String[] args) {
//System.in:读取字节流 InputStreamReader字节流->字符流转换的一个桥梁
//BufferedReader类从字符输入流中带缓存功能的读取字符readline()按行读取字符串
//eg:
//37 65
//74 415
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line="";//每次从in里面读取一行字符串
try {
while((line=in.readLine())!=null){//只要还有行就继续读取每次读取一行放到line字符串里
String[] s=line.split(" +");//+表示会将多个空格看成一个空格
int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
System.out.println(a+b);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}