1.读取文件版:package excel;
import java.io.*;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
FileReader fileReader = new FileReader("C:\\Users\\sinosoft\\Desktop\\test.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String m;
while ((m = bufferedReader.readLine()) != null) {
String[] s = m.split(" ");
int num = 0;
for (int i = 0; i < s.length; i++) {
num += Integer.parseInt(s[i]);
}
System.out.println(num);
}
}
}
2.手动输入版package excel;
import java.io.*;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
while (true){
int i = 3,i1 = 0,num = 0;
while (i > 0){
i1 = scanner.nextInt();
num+=i1;
i--;
}
System.out.println(num);
}
}
}
|