Calculate the average rainfall over a period of years

The attached program has been written using nested for statements.  The program asks the users the enter the number of years and the inches of rain for each month.  Lastly provide the average inches of rain for the entire period.  

My program is about 90% completed, I'm having problem with where to add the for statement needed to display the average rainfall per month for the entire period?
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
 
 
 
public class Rain1
{
	public static void main(String[] args)
	{
	
	Scanner in=new Scanner(System.in);
 	int years;
	int month=12;
 	double total=0;
	double average;
	 double months[];
	String input;
	
	months=new double[12];
	
	DecimalFormat dollar = new DecimalFormat("#,##0.00");
 
		input = JOptionPane.showInputDialog("Number of years? "); 
		
		years = Integer.parseInt(input);
		
		
		for(int y=1; y<=years; y++)
 
		{
			System.out.println("Enter the rainfall (in inches for year #"+y+":");
		
		}	
 
				
		for(int n=1; n<=month; n++ )
		{
		System.out.println("Enter the rainfall (in inches) for month #"+n+":");
		months[n-1] = in.nextInt();
		}
	
		total = 0;
		for(int i=0; i<12;i++)
		{
			total=total+months[i];
		}
			System.out.println("The total rainfall for the year is "+ total);
						
			average = total/12;
			System.out.println("The average rainfall of the year is "+ average);
			
		}
	}

Open in new window

gkilgoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

humanonomicsCommented:
Try this
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
 
 
 
public class Rain1
{
    public static void main(String[] args)
    {
        
        Scanner in=new Scanner(System.in);
        int years;
        int month=12;
        double total=0;
        double average;
        double months[];
        String input;
        double bigTotal=0;
        months=new double[12];
        
        DecimalFormat dollar = new DecimalFormat("#,##0.00");
 
		input = JOptionPane.showInputDialog("Number of years? "); 
		
		years = Integer.parseInt(input);
		
		for(int y=1; y<=years; y++)
		{
				System.out.println("Enter the rainfall (in inches for year #"+y+":");
					
			for(int n=1; n<=month; n++ )
			{
				System.out.println("Enter the rainfall (in inches) for month #"+n+":");
				months[n-1] = in.nextInt();
			}
 
			total = 0;
			for(int i=0; i<12;i++)
			{
					total=total+months[i];
			}
			bigTotal += total;
			System.out.println("The total rainfall for the year # " + y + "is "+ total);
									
			average = total/12;
			System.out.println("The average rainfall of the year # " + y + " is "+ average);
					
		}
		System.out.println("The total rainfall of all the years is "+ bigTotal);
		average = bigTotal/(years*12);
		System.out.println("The average rainfall of all the years is "+ average);
 
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gkilgoreAuthor Commented:
Thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.