// Marty Stepp, CSE 142, Autumn 2008 // This program prompts the user to enter several days' worth of temperatures // and computes the average temperature and how many days were above average. // // This version of the program does not work yet, because we cannot tell // how many days were above average (we will need an array for this). import java.util.*; // for Scanner 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 sum = 0; int aboveAverage = 0; // read each day's temperature // 45 44 39 48 37 46 53 for (int i = 1; i <= days; i++) { System.out.print("Day " + i + "'s high temp: "); int temp = console.nextInt(); sum += temp; // The code below won't work because we don't know the average yet // if (temp > average) { // aboveAverage++; // } } double average = (double) sum / days; System.out.printf("Average temp = %.1f\n", average); } }