Advertisement
mmayoub

School11, 170910, Ex04

Sep 10th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package myPkg;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex04 {
  6.  
  7.     public static void main(String[] args) {
  8.         int n = 5;
  9.  
  10.         Scanner in = new Scanner(System.in);
  11.         int max = 0;
  12.         int min = 100;
  13.         int sum = 0;
  14.         double avg;
  15.         int pass = 0;
  16.  
  17.         System.out.println("Enter " + n + " grades:");
  18.         for (int i = 0; i < n; i = i + 1) // i+=1
  19.         {
  20.             int x = in.nextInt();
  21.  
  22.             // max grade
  23.             if (x > max)
  24.                 max = x;
  25.  
  26.             // min grade
  27.             if (x < min)
  28.                 min = x;
  29.  
  30.             // average of grades
  31.             sum = sum + x; // sum +=x;
  32.  
  33.             // pass number
  34.             if (x >= 55)
  35.                 pass = pass + 1;
  36.         }
  37.  
  38.         avg = 1.0 * sum / n; // avg = (double)sum/n;
  39.  
  40.         System.out.println("max grade is: " + max);
  41.         System.out.println("min grade is: " + min);
  42.         System.out.println("average is: " + avg);
  43.         System.out.println("pass number is: " + pass);
  44.         System.out.println("faild number is: " + (n - pass));
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement