import java.util.*; // for Scanner import java.io.*; // for File // Reads in 5 doubles from an input file, printing each one out, and // printing out the sum of the 5 numbers after we've read all of them. public class Echo { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("numbers.txt")); double sum = 0.0; // NOTE: this hardcoded 5 in the loop bound means that we are assuming // that there are at least 5 numbers in the file, otherwise our // program will crash for (int i = 1; i <= 5; i++) { double next = input.nextDouble(); System.out.println("number = " + next); sum += next; } double rounded = Math.round(sum * 10.0) / 10.0; System.out.println("Sum = " + rounded); } }