// program to read in real numbers from a file and print // the sum of all the numbers on each line and the total // of all numbers in the file import java.util.*; import java.io.*; public class SumFile { public static void main(String[] args) throws FileNotFoundException { Scanner file = new Scanner(new File("numbers.txt")); double fileSum = 0; // read each double // add to sum // stop....when? // next(), nextInt(), ... // nextLine() while (file.hasNextLine()) { String line = file.nextLine(); Scanner nums = new Scanner(line); double lineSum = 0; while (nums.hasNextDouble()) { double num = nums.nextDouble(); lineSum += num; } fileSum += lineSum; System.out.println("line sum = " + lineSum); } System.out.println("file sum = " + fileSum); } }