// CSE 142 Lecture 14 // Files // Scans a file of temperature data and prints the change // in temparature from day to day. import java.io.*; // For File import java.util.*; // For Scanner public class Weather { public static void main(String[] args) throws FileNotFoundException { File f = new File("weather.txt"); Scanner input = new Scanner(f); // The problem stated the file starts with a whole number. double prev = input.nextDouble(); // While there are more tokens in the file. while (input.hasNext()) { if (input.hasNextDouble()) { double cur = input.nextDouble(); System.out.printf("%.2f to %.2f, change = %.2f\n", prev, cur, cur - prev); prev = cur; } else { // some random String...just throw it away input.next(); } } } }