grodek118

Average Rainfall

Nov 18th, 2022
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args){
  8.  
  9.        Scanner scanner = new Scanner(System.in);
  10.  
  11.         int years;
  12.         int rainfallPerMonth;
  13.         int sumRainfall = 0;
  14.  
  15.         System.out.print("Enter the number of years: ");
  16.         years = scanner.nextInt();
  17.  
  18.         for (int i = 0; i < years; i++)
  19.         {
  20.             for (int y = 1; y <= 12; y++)
  21.             {
  22.                 System.out.print("Insert inches of rainfall for month " + y + ": " );
  23.                 rainfallPerMonth = scanner.nextInt();
  24.  
  25.                 sumRainfall += rainfallPerMonth;
  26.             }
  27.         }
  28.  
  29.         System.out.println("Number of months: " + (years * 12));
  30.         System.out.println("Total inches of rainfall: " + sumRainfall);
  31.         System.out.println("Average rainfall per month: " + (sumRainfall / (years * 12)));
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment