Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago