Advertisement
mmayoub

Ex1,Numbers in loop16.12.2022

Dec 16th, 2022
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. package proj16122022;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex01 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.        
  10.         double x;
  11.         int count=0;
  12.         double sum=0;
  13.         double max=Double.MIN_VALUE;
  14.         double min=Double.MAX_VALUE;
  15.         int count55To100=0;
  16.        
  17.         System.out.print("Eneter a positive number: ");
  18.         x = in.nextDouble();
  19.        
  20.         while (x>0) {
  21.             // process
  22.             count++; // add one to counter
  23.             sum = sum + x; // add x to sum of numbers
  24.            
  25.             if (x>max) {
  26.                 max = x;
  27.            
  28.             if (x<min) {
  29.                 min = x;
  30.             }
  31.            
  32.             if (x>=55 && x <=100 ) {
  33.                 count55To100++;
  34.             }
  35.            
  36.             // get a new number
  37.             System.out.print("Eneter a positive number: ");
  38.             x = in.nextDouble();
  39.         }
  40.        
  41.         System.out.println("End of data");
  42.         System.out.println("count = " + count);
  43.         System.out.println("sum = " + sum);
  44.         //double avg = sum/count;
  45.         //System.out.println("average = " + avg);
  46.         System.out.println("average = " + sum/count);
  47.         System.out.println("max = " + max);
  48.         System.out.println("min = " + min);
  49.         System.out.println("count55To100 = " + count55To100);
  50.        
  51.        
  52.     }
  53.  
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement