// Ayaz Latif // 07/31/2020 // CSE142 // TA: Grace Hopper // Asks the user for the temperatures on some number of days (specified by the user) // and reports the average temperature across those days, as well as how many days' // temperatures were above averge temperature. import java.util.*; public class Temperatures { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("How many days? "); int numDays = console.nextInt(); double[] temps = new double[numDays]; double tempSum = 0.0; int count = 0; for (int i = 0; i < temps.length; i++) { System.out.print("Day " + (i + 1) + "'s temperature? "); temps[i] = console.nextDouble(); tempSum += temps[i]; } double average = tempSum / numDays; // a standard **array traversal** pattern for (int i = 0; i < temps.length; i++) { // do something with temps[i] // remember, temps[i] is accessing the element in the temps array // (which contain the temperatures that were inputted by the user) // at index i...because i goes from 0 to < temps.length, this will // get each element in the temps array and use them in the check below. if (temps[i] > average) { count++; } } System.out.println("Average temperature: " + average); System.out.println("Num days above average is " + count); } }