刚学java 求助。
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);
}
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);
}
}
}
连帅帅 发表于 2021-9-10 13:50
1.读取文件版:
2.手动输入版
dddddddddddddddd嘀嘀嘀
页:
[1]