Temps - System.out.println (); System.out.println...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// ************************************************************** // Temps.java // // This program reads in a sequence of hourly temperature // readings (beginning with midnight) and prints the maximum // temperature (along with the hour, on a 24-hour clock, it // occurred) and the minimum temperature (along with the hour // it occurred). // ************************************************************** import java.util.Scanner; public class Temps { public static void main (String[] args) { final int HOURS_PER_DAY = 24; Scanner scan = new Scanner (System.in); int temp; // a temperature reading int maxTemp = -1000; // the max temp read so far int timeOfMax = 0; int minTemp = 1000; int timeOfMin = 0; // print program heading
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println (); System.out.println ("Temperature Readings for 24 Hour Period"); System.out.println (); for (int hour = 0; hour < HOURS_PER_DAY; hour++) { System.out.print ("Enter the temperature reading at " + hour + " hours: "); temp = scan.nextInt(); if (temp > maxTemp) { maxTemp = temp; timeOfMax = hour; } if (temp < minTemp) { minTemp = temp; timeOfMin = hour; } } // Print the results System.out.println(); System.out.println("The maximum temperature is " + maxTemp); System.out.println("It occurred at hour " + timeOfMax); System.out.println("The minimum temperature is " + minTemp); System.out.println("It occurred at hour " + timeOfMin); System.out.println(); } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online