import java.util.Scanner; import java.io.File; public class Parse { public static void parseString() { Scanner tokens = new Scanner("A squid eating dough is fast and bulbous"); while(tokens.hasNext()) { String token = tokens.next(); System.out.println("token = " + token); } } public static void parseFile() { try { Scanner tokens = new Scanner(new File("beefheart.txt")); while(tokens.hasNext()) { String token = tokens.next(); System.out.println("token = " + token); } } catch(Exception e) { System.err.println(e); } } public static void addNumbers() { double total = 0; Scanner numbers = new Scanner("23 3.14 45 21 -19"); while(numbers.hasNextDouble()) { double num = numbers.nextDouble(); total = total + num; } System.out.println("total = " + total); } public static void main(String[] args) { //parseString(); //parseFile(); addNumbers(); } }