/*
File Score.txt number of the sum and average are:
sum = 448.9
Average = 44.9
*/
/**Score.txt:
-------------------------------------------------
33.5 88 72 25 11.3
32.11 56 76 43 12
*/
import java.util.Scanner;
public class TheFileScore {
public static void main(String[] args) throws Exception {
java.io.File file = new java.io.File("Score.txt");
Scanner input = new Scanner(file);
double sumNumber = 0;
int count = 0;
while (input.hasNext()) {
sumNumber += input.nextDouble();
count++;
}
double average = sumNumber / count;
System.out.println("File Score.txt number of the sum and average are: ");
System.out.printf("sum = %.1f\n", sumNumber);
System.out.printf("Average = %.1f\n", average);
}
}
Introduction to Java Programming编程题9.18<IO流处理>
最新推荐文章于 2023-07-02 09:44:31 发布