import java.io.*; import java.util.*; /* * CSE 142 * Lecture 07.27.18 | Arrays * * This program prompts a user for a desired number of daily temperatures, * printing out the average of the temperatures as well as how many days * had temperatures above that average. */ public class Weather { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("How many days? "); int numDays = console.nextInt(); double total = 0; double[] temps = new double[numDays]; for (int i = 0; i < numDays; i++) { System.out.print("Day #" + (i + 1) + "'s temperature? "); double today = console.nextDouble(); temps[i] = today; total += today; } double average = total / numDays; int numDaysAboveAvg = 0; for (int i = 0; i < temps.length; i++) { double temp = temps[i]; if (temp > average) { numDaysAboveAvg++; } } System.out.println("Average temperature: " + average); System.out.println("There were " + numDaysAboveAvg + " days above the average."); } }