So, first, i'm not able to get the program to accept output for each iteration. Can anyone help? My code is below.
import java.util.Scanner;
import java.text.DecimalFormat;
public class RainFall {
public static void main(String[] args) {
// TODO Auto-generated method stub
int Years, Months;
double Rain, totalRain = 0.0, averageRain;
Scanner scan = new Scanner(System.in);
DecimalFormat fmt = new DecimalFormat("0.##");
System.out.print("For how many years did it rain? ");
Years = scan.nextInt();
while (Years < 1) {
System.out.print("Enter data for at least one year, for how many years did it rain? ");
Years = scan.nextInt();
}
System.out.print("For how many months did it rain? ");
Months = scan.nextInt();
System.out.println();
for (int Y = 1; Y <= Years; Y++)
System.out.print("Enter the amount of rainfall for year " + Y + ": ");
Rain = scan.nextDouble();
for (int M = 1; M <= Months; M++)
System.out.println("Enter the amount of rainfall for month " + M);
Rain = scan.nextDouble();
while (Rain < 0.0) {
System.out.print("Negative rainfall invalid! Enter a positive number: ");
Rain = scan.nextDouble();
}
}
}