-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson 6.java
More file actions
49 lines (42 loc) · 1.41 KB
/
Lesson 6.java
File metadata and controls
49 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Student: Griffin Gowdey.
// Instructor: Daniel Goodman.
// Class Number: ITSE1479-86039.
// Class Name: Java Programming.
// Semester: Fall 2020.
// Lesson 6.
/*
Assignment:
Read twelve temperature values (one for each month) and display
the number of the month with the highest temperature. For example,
according to http://worldclimate.com, the average maximum
temperatures for Death Valley are (in order by month, in degrees
Celsius):
18.2 22.6 26.4 31.1 36.6 42.2
45.7 44.5 40.2 33.1 24.2 17.6
In this case, the month with the highest temperature (45.7 degrees
Celsius) is July, and the program should display 7. Your program
should read twelve temperature values and print the month with
the highest temperature.
*/
import java.util.Scanner;
public class Lesson6
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Please enter twelve temperature values: ");
double highestValue = highestValue = in.nextDouble();
int highestMonth = 1;
for (int currentMonth = 2; currentMonth <= 12; currentMonth++)
{
double nextValue = in.nextDouble();
if (nextValue > highestValue)
{
highestValue = nextValue;
highestMonth = currentMonth;
}
}
System.out.println("Highest Month: " + highestMonth);
System.out.println("Highest Value: " + highestValue);
}
}