// This program reads all tokens from a file, adding them up if they are // numbers and otherwise reporting them as "bad" tokens. import java.io.*; import java.util.*; 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.nextDouble(); System.out.println("number = " + next); sum = sum + next; } else { String bad = input.next(); System.out.println("skipping bad token " + bad); } } System.out.println("sum = " + sum); } }