Respuesta :
Answer:
The java program is as follows. Â
import java.lang.*; Â
import java.util.Scanner; Â
public class Main Â
{ Â
//array declaration Â
static int weekdays=7; Â
static int[] snowfall_inch = new int[weekdays]; Â
static String[] snowfall_date = new String[weekdays]; Â
//variables to store average and maximum Â
static double avg; Â
static int max; Â
public static void main(String[] args) { Â
Scanner sc = new Scanner(System.in); Â
System.out.print("Enter the month: "); Â
String month = sc.next(); Â
for(int n=0; n<weekdays; n++) Â
{ Â
System.out.print("\nEnter the date for day "+(n+1)+ ": "); Â
snowfall_date[n] = sc.next(); Â
System.out.print("Enter the inches of snowfall for day "+(n+1) +": "); Â
snowfall_inch[n] = sc.nextInt(); Â
avg = avg + snowfall_inch[n]; Â
} Â
avg = avg/weekdays; Â
System.out.printf("The average snowfall for the week is %.4f",avg); Â
for(int n=0; n<weekdays-1; n++) Â
{ Â
if(snowfall_inch[n] < snowfall_inch[n+1]) Â
max=snowfall_inch[n+1]; Â
} Â
System.out.println("\nThe maximum snowfall for the week is "+max); Â
} Â
} Â
OUTPUT Â
Enter the date for day 2: 12-2-2019
Enter the inches of snowfall for day 2: 23 Â
Enter the date for day 3: 12-3-2019
Enter the inches of snowfall for day 3: 13 Â
Enter the date for day 4: 12-4-2019
Enter the inches of snowfall for day 4: 14 Â
Enter the date for day 5: 12-5-2019
Enter the inches of snowfall for day 5: 34 Â
Enter the date for day 6: 12-6-2019
Enter the inches of snowfall for day 6: 34 Â
Enter the date for day 7: 12-7-2019
Enter the inches of snowfall for day 7: 22
The average snowfall for the week is 21.7143 Â
The maximum snowfall for the week is 34 Â
Explanation:
1. Two arrays are declared to store dates and snowfall inches with string and integer datatypes respectively. Â
2. Variables are declared to store maximum and average snowfall values with integer and double datatypes respectively. Â
3. User input is taken for the month, and the dates and snowfall inch values for a week. The input is taken in for loop. Â
4. Next, for loop is used to find the average and maximum snowfall of the week. Â
5. These values are displayed to the user as shown in the output.