Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program: Program to calculate average rainfall over a given period of years mont

ID: 3604251 • Letter: P

Question

Program: Program to calculate average rainfall over a given period of years months ["January", "February", "March", "April", "May", "June","July","August","September", "October", "November", "December"] # lake number of years as input numYearsint (input("Enter number of years:")) total = 0 # loop to execute for numYears time for idx in range(0,numYears) print("Year",idx+1) # loop to execute for 12 times for jdx in range(0,12) monthly float (input("Enter rainfall for ". format (months[jdx]) total + monthly totalMonths numYears 12 print(" print(" Total number of months: ",totalMonths) print(" Total rainfall: ", total) print("Average rainfall: ",total/totalMonths)

Explanation / Answer

import java.util.*;

public class AverageRainfall{

public static void main(String[] args)

{

Scanner sc=new Scanner(System.in);

int month=12;

double total=0;

double average;

int months[];

months = new int[12];

for(int n=1; n<=month; n++ )

{

System.out.println("Enter the rainfall (in inches) for month #"+n+":");

months[n-1] = sc.nextInt();

}

total = 0;

for(int i=0; i<12;i++)

{

total=total+months[i];

}

System.out.println("The total rainfall for the year is "+ total);

average = total/12;

System.out.printf("The average rainfall of the year is %.2f", average);

}

}

/*

Enter the rainfall (in inches) for month #1:

12

Enter the rainfall (in inches) for month #2:

12

Enter the rainfall (in inches) for month #3:

13

Enter the rainfall (in inches) for month #4:

14

Enter the rainfall (in inches) for month #5:

12

Enter the rainfall (in inches) for month #6:

123

Enter the rainfall (in inches) for month #7:

34

Enter the rainfall (in inches) for month #8:

12

Enter the rainfall (in inches) for month #9:

323

Enter the rainfall (in inches) for month #10:

121

Enter the rainfall (in inches) for month #11:

12

Enter the rainfall (in inches) for month #12:

23

The total rainfall for the year is 711.0

The average rainfall of the year is 59.25

*/