import java.io.*; import java.util.*; // This program reads from a file of temperatures (i.e. doubles) and reports // the change between the temperatures. weather.txt has only doubles. // weather2.txt has our temperatures but also some other data we don't want // to process. This program handles both types of data files. public class Temperatures { public static void main(String[] args) throws FileNotFoundException { File f = new File("weather2.txt"); Scanner input = new Scanner(f); double previous = input.nextDouble(); while (input.hasNext()) { if (input.hasNextDouble()) { double next = input.nextDouble(); System.out.printf("%.1f to %.1f, change = %.1f\n", previous, next, (next - previous)); previous = next; } else { input.next(); } } } }