Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class WeatherMonitor {
- /*
- * Program: WeatherMonitor.java
- * Purpose: Read temperature data from file, show daily difference in temperature
- * Creator: Chris Clarke
- * Created: 04.12.2014
- */
- /* Note: You need a text file called "weather.txt", containing the following:
- 16.2 23.5 19.1 7.4 22.8 18.5 -1.8 14.9
- */
- public static void main(String[] args) throws IOException, FileNotFoundException {
- File f = new File("weather.txt");
- Scanner filescan = new Scanner(f);
- double oldTemp, newTemp=999;
- double change;
- boolean firstTime = true;
- while (filescan.hasNext()) {
- if (firstTime) {
- oldTemp = filescan.nextDouble();
- firstTime = false;
- } else {
- oldTemp = newTemp;
- } // if
- newTemp = filescan.nextDouble();
- change = newTemp - oldTemp;
- System.out.printf("%.1f to %.1f, change = %.1f%n",oldTemp,newTemp,change);
- } // while
- } // main()
- } // class WeatherMonitor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement