repl.it
@panniu/

Weather

Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
Main.java
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
import java.util.*;


public class Main {
  public static void main(String[] args) {
    Scanner kb = new Scanner(System.in);
	System.out.print("How many days' temperatures? ");
	int days = kb.nextInt();
	int[] temps = new int[days];
	int totalTemp = 0;
	int daysAboveAvg = 0;
	double avgTemp = 0;

	for(int i = 0; i < days; i++){
		System.out.print("Day " + (i + 1) + "'s high temp: ");
		int temp = kb.nextInt();
		totalTemp += temp;
		temps[i] = temp;
	}

	avgTemp = Math.round((double) totalTemp/days * 100) / 10;
	avgTemp /= 10;

	System.out.println("Average temp = " + avgTemp);

	for(int i = 0; i < days; i++){
		if(temps[i] > avgTemp){
			daysAboveAvg ++;
		}
	}

	System.out.println(daysAboveAvg + " days were above average.\n");

	System.out.println("Temperature: " + Arrays.toString(temps));
	Arrays.sort(temps);
	System.out.println("Two coldest days: " + temps[0] + ", " + temps[1]);
	System.out.println("Two hottest days: " + temps[temps.length - 1] + ", " + temps[temps.length - 2]);


  }
}
Fetching token
?