Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions