// Allison Obourn, CSE 142 // Asks the user for a number of temperatures and then for // that many temperatures. Outputs the average of the temperatures // and the number of temperatures above average. import java.util.*; public class Weather { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("How many days' temperatures? "); int days = console.nextInt(); int[] temps = new int[days]; int total = 0; for (int i = 0; i < days; i++) { System.out.print("Day " + (i + 1) + "'s high temperature: "); temps[i] = console.nextInt(); total += temps[i]; } double average = (double) total / temps.length; System.out.println("Average temp = " + average); int above = 0; for(int i = 0; i < temps.length; i++) { if(temps[i] > average) { above++; } } System.out.println(above + " days were above average."); System.out.println("Temperatures: " + Arrays.toString(temps)); Arrays.sort(temps); System.out.println("Two coldest days: " + temps[0] + ", " + temps[1]); System.out.println("Two hotest days: " + temps[temps.length - 1] + ", " + temps[temps.length - 2]); } }