import java.util.Scanner; /** Program: High and low Temperatures. This program calculates the high and low temperatures from 24 hourly temperature readings adapted from Nell Dale, C++ textbook J. Dalbey 2/25/00 Modified to use Scanner 5/2008 */ public class HiLoTemps { public static void main(String[] args) { final int kNumHours = 24; // Number of hours in time period int temperature; // An hourly temperature reading int hour; // Loop control variable for hours in a day int high; // highest temperature so far int low; // lowest temperature so far high = Integer.MIN_VALUE; // Set high to impossibly low value low = Integer.MAX_VALUE; // Set low to impossibly high value Scanner console = new Scanner(System.in); System.out.println("Enter the temperature readings: "); hour = 1; // initialize loop control // Loop to control reading all the input data while (hour <= kNumHours) { // Read a data item temperature = console.nextInt(); // Update the high or low if (temperature < low) // lowest temperature so far? { low = temperature; } if (temperature > high) // highest temperature so far? { high = temperature; } // increment loop counter hour++; } // Print high and low temperatures System.out.println("high temperature is " + high + "\n"); System.out.println("low temperature is " + low + "\n"); } }