Answer:
import java.util.Scanner;
public class ANot {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the month name:");
String month1 = input.next();
System.out.println("Enter the amount of rain for "+month1);
double month1Rain = input.nextDouble();
System.out.println("Enter the second month: ");
String month2 = input.next();
System.out.println("Enter the amount of rain for "+month2);
double month2Rain = input.nextDouble();
System.out.println("Enter the Third month: ");
String month3 = input.next();
System.out.println("Enter the amount of rain for "+month3);
double month3Rain = input.nextDouble();
double averageRainfall = (month1Rain+month2Rain+month3Rain)/3;
System.out.printf("Average Rainfall is: %,.2f ", averageRainfall);
}
}
Explanation:
This is written in Java Programming language
- Import the scanner class to prompt user for the inputs (Months and amount of rainfall for each month)
- Find the average of the three rainfall amount by adding up and dividing by 3
- Output the average. Pay particular attention to the use of java's printf in order to print the average to 2 decimal places