Advertisement
Shavit

P. 167 Ex. 7.6

Oct 29th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class CalcAvgAndCountLargerThan50 {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         final int LIMIT = 50;
  12.         int length;
  13.         double num;
  14.         double sum = 0;
  15.         double average;
  16.         Scanner in = new Scanner (System.in);
  17.        
  18.         System.out.println("Enter length of input list:");
  19.         length = in.nextInt();
  20.        
  21.         for(int i = 1; i<=length; i++)
  22.         {
  23.             System.out.println("Enter a number:");
  24.             num = in.nextDouble();
  25.             if(num > LIMIT)
  26.                 sum = sum + num;
  27.         }
  28.         average = sum / length;
  29.         System.out.println("The average of the numbers larger than 50 is " + average);
  30.        
  31.         in.close();
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement