Question: /** This program reads 12 temperatures corresponding to 12 months, and prints the month number with the highest average temperature, followed by the month number

/** This program reads 12 temperatures corresponding to 12 months, and prints the month number with the highest average temperature, followed by the month number with the lowest average temperature. */ import java.util.* ;

public class MaxFinder { public static void main(String[] args) { //average high temperatures for Toronto according to gocanada. String temperatures = "-2 -1 4 11 18 24 27 26 21 14 7 0" ;

Scanner scanner = new Scanner(temperatures) ; int hottestTemp = 0 ; int hottestMonth = 0 ; int coldestTemp = 0 ; int coldestMonth = 0 ;

//-----------Start below here. To do: approximate lines of code = 14 // 0. initialize month

//1. write a while loop that reads temperatures from scanner (assume you do not know how many values there will be, so use the hasNextInt() method) ; // Hint: use scanner.hasNextInt() in the loop condition // Don't forget to increment variable month //2. if this is the first month or an extreme month, update the hottestMonth,hottestTemp or coldestMonth,coldestTemp variables ; // an extreme month means the temperature for this month is > the current hottest temperature or // the temperature is < the current coldest temperature. That is, write two if statements and corresponding code - one for hottest check // and one for coldest //3. End code here

System.out.println("Expected: ") ; System.out.println("Hottest month is " + hottestMonth + " ("+hottestTemp+" C)") ; System.out.println("Coldest month is " + coldestMonth + " ("+coldestTemp+" C)") ; System.out.println(" ");

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!