import java.util.*; // for Scanner import java.io.*; // for File // Reads in all the tokens in the given file, printing out and adding // up all the numbers that can be parsed as doubles. public class Echo2 { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("numbers2.txt")); double sum = 0.0; while (input.hasNext()) { if (input.hasNextDouble()) { double next = input.next(); System.out.println("number = " + next); sum += next; } else { System.out.println("not a double, can't read: " + input.next()); } } double rounded = Math.round(sum * 10.0) / 10.0; System.out.println("Sum = " + rounded); } }