import java.util.*; import java.io.*; // Reads doubles from a text file called "numbers.txt" and // keeps a cumulative sum, printing the numbers and final sum. // NOTE: we assume here that the given file only contains doubles. public class Numbers { public static void main(String[] args) throws FileNotFoundException { File numbersFile = new File("numbers.txt"); Scanner input = new Scanner(numbersFile); double sum = 0.0; while (input.hasNext()) { double num = input.nextDouble(); System.out.println(num); sum += num; } System.out.println(sum); } }