What is orographic rainfall?

Java program help.. Write a program using loop and file to collect the rainfall over a period of years?

  • Write a program using loop and file to collect the rainfall over a period of years and calculate the average rainfall: 1. ask the user for the number of years. Perform input validation on the number of years to make sure it is at least 2 years 2. using a nested loop to collect the inches of rainfall for each month over those years. Perform input validation for rainfall to make sure it is positive 3. calculate the total inches of rainfall, and the average rainfall per month for the entire period. 4. write each month's rainfall, total inches of rainfall, and the average rainfall into a file named rainfall.txt

  • Answer:

    import java.util.*; public class rainfall { public static void main(String []a) { int years; Scanner s=new Scanner(System.in); double xx = new double[years]; do { System.out.println("Enter number of years"); years=s.nextInt(); }while(years<=2); double total=0; for(int i=0;i<years;i++) { do { System.out.println("Enter rainfall in inches (positive)"); double x=s.nextDouble(); } while(x<0); total+=x; xx[i]=x; } for(int i=0;i<years;i++) System.out.println("Month=" + (i+1) + "\t" + "Raainfall="+ xx[i]); double avg=total/years; System.out.println("Total Rainfall="+ total + "Average rainfall="+avg); } }

pinder at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.