Question: My Java program below runs, but the output for average and lowest display at zero. Can you tell me why this is happening so I

My Java program below runs, but the output for average and lowest display at zero.

Can you tell me why this is happening so I can fix it? I followed the script in my book, but it still doesn't work.

Thank you :)

public class Rainfall { public static void main(String[] args) { final int MONTHS_IN_YEAR = 12; double[] rainfallTotal = new double[MONTHS_IN_YEAR]; totalRainfall(rainfallTotal); averageRainfall(rainfallTotal); lowestRainfall(rainfallTotal); } public static void totalRainfall(double[] rainfallTotal) { double total = 0; Scanner keyboard = new Scanner(System.in); for(int index = 0; index < rainfallTotal.length; index++) { System.out.print("Please enter the amount of rainfall for month " + (index +1) + " : "); double userInput = keyboard.nextDouble(); total = total + userInput; } System.out.println("The total rainfall is " + total); } public static void lowestRainfall(double[] rainfallTotal) { double lowest = rainfallTotal[0]; for (int index = 0; index < rainfallTotal.length; index++) { if (rainfallTotal[index] < lowest); { lowest = rainfallTotal[index]; } } System.out.println("The lowest rainfall is " + lowest); } public static void averageRainfall(double[] rainfallTotal) { double total = 0; double average; for(int index = 0; index < rainfallTotal.length; index++) total = total + rainfallTotal[index]; average = total / rainfallTotal.length;

System.out.println("The average rainfall is " + average);

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!