-
Notifications
You must be signed in to change notification settings - Fork 522
/
Copy pathCode04_ReadByLine.java
41 lines (33 loc) · 1.16 KB
/
Code04_ReadByLine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package class019;
// 展示acm风格的测试方式
// 测试链接 : https://www.nowcoder.com/exam/test/70070648/detail?pid=27976983
// 其中,7.A+B(7),就是一个没有给定数据规模,只能按行读数据的例子
// 此时需要自己切分出数据来计算
// 请同学们务必参考如下代码中关于输入、输出的处理
// 这是输入输出处理效率很高的写法
// 提交以下的code,提交时请把类名改成"Main",可以直接通过
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class Code04_ReadByLine {
public static String line;
public static String[] parts;
public static int sum;
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
while ((line = in.readLine()) != null) {
parts = line.split(" ");
sum = 0;
for (String num : parts) {
sum += Integer.valueOf(num);
}
out.println(sum);
}
out.flush();
in.close();
out.close();
}
}