// Tyler Rigsby, CSE 142 // Prompts for temperatures and reports statistics about them // Assume every day has a temperature between 0 and 100 // Sample output: // // How many days' temperatures to input? 5 // Day 1 temp: 83 // Day 2 temp: 85 // Day 3 temp: 54 // Day 4 temp: 74 // Day 5 temp: 86 // // Average temperature: 76 // High temperature: 86 // Low temperature: 54 import java.util.*; public class Temperatures { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("How many days' temperatures to input? "); int days = console.nextInt(); // need these variables declared before the loop so that they're in scope int sum = 0; int max = 0; int min = 100; for (int i = 1; i <= days; i++) { System.out.print("Day " + i + " temp: "); int temp = console.nextInt(); sum = sum + temp; // two ways to do a cumulative max/min: if (temp > max) { max = temp; } min = Math.min(min, temp); } System.out.println("Average temperature: " + Math.round(1.0 * sum / days)); System.out.println("High temperature: " + max); System.out.println("Low temperature: " + min); } }