No errors pop up using NetBeans
public class Source1
{
public static void main(String[] args)
{
int[] month = new int [12];
double[] rain = new double [12];
Scanner keyboard = new Scanner(System.in);
for (int index = 0; index < rain.length; index++)
{
System.out.print("Enter the rainfall for month "+(index+1)+": ");
rain[index] = keyboard.nextDouble();
while(rain[index]<0)
{
System.out.print("Invalid. Enter a positive number for rainfall: ");
rain[index]=keyboard.nextDouble();
}
}
TotalRainfall(rain);
Average(rain);
Most(rain, month);
Least(rain, month);
}
public static void TotalRainfall(double[] rain)
{
double total = 0;
for (int index=0; index<rain.length; index++)
{
total += rain[index];
}
System.out.println("\nTotal rainfall for this year is : "+ total);
}
public static void Average(double[] rain)
{
double total = 0;
double average;
for (int index = 0; index<rain.length; index++)
{
total += rain [index];
}
average = total/12;
System.out.println("Average rainfall for this year is : "+ average);
}
public static void Most(double[] rain, int[] month)
{
double most;
int highmonth;
most = (int) month[0];
highmonth = (int) month[0];
for (int index=0; index<rain.length; index++)
{
if (rain[index]>most)
{
most= rain[index];
highmonth= index + 1;
}
}
System.out.println("Month with the most rainfall is " + highmonth +" with a rainfall of "+ most );
}
public static void Least(double[] rain, int[] month)
{
double least;
int lowmonth;
least = (int) month[0];
lowmonth = (int) month[0];
for (int index=0; index<rain.length; index++)
{
if (rain[index]<least)
{
least=rain[index];
lowmonth= index + 1;
}
}
System.out.println("Month with the least rainfall is " + lowmonth +" with a rainfall of "+ least );
}
}
This post has been edited by macosxnerd101: 02 December 2015 - 01:25 PM
Reason for edit:: Please use code tags

New Topic/Question
Reply


MultiQuote





|