Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write a program that uses nested loops to collect data and calculate t

ID: 3624943 • Letter: I

Question

I need to write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. First the program should ask for the number of years, The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.

Input Validation: Do Not accept a number less than 1 for the number of years. Do not accept a negative numbers for the monthly rainfall.

This is what i got

import java.text.DecimalFormat;
  import java.io.*;
import java.util.*;
public class RainFall{
public static void main(String[] args)     
  {              
      Scanner kb=new Scanner(System.in);     
      int years;
      int month=12;       
      double total=0;       
      double average;
      int months[];      
      String input; 

      months = new int[12];              
      DecimalFormat df = new DecimalFormat("##0.00");                
      System.out.println("Enter the number of years you wish to calculate. "); 
      input = kb.nextLine();


      for(int y = 1; y<=12; y++)               
      {       
          System.out.println("Enter the amount of rainfall in inches for year #"+y+":");  
        years = Integer.parseInt(input);
      while (y < 1)
      {
          System.out.println("Do not accept a number less than 1 for the number of years.");
        }
      for(int m = 1; m<=12; m++ )
      {               
          System.out.println("Enter the amount of rainfall in inches for month #" + m + ":");

          months[m-1]= kb.nextInt(); 
          while (m < 0)
          {
          System.out.println("Do not accept negative numbers for the monthly rainfall.");   
           }
      }                      

      for(int i=0; i<12;i++) 
      {                      
         total= total+months[i];              
      }   

      System.out.println("The total amount of rainfall for year " + y + " is " + total);  
      average = total/12; 
      System.out.println("The average of rainfall for year " + y + " is " + average);

    }
}

}

Im having trouble, when it ask the user to Enter the number of years it wishes to calculate, when i input any number the loop goes on forever how do i fix this and do i need to add anything else for this to work please help

Explanation / Answer

CHANGE THE FOLLOWING CODE OF THE FIRST FOR-LOOP for(int y = 1; y