Advertisement
YavorGrancharov

Grades

Mar 18th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Grades {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.         int num = Integer.parseInt(console.nextLine());
  7.         int top = 0;
  8.         int betweenFour = 0;
  9.         int betweenThree = 0;
  10.         int fail = 0;
  11.         double average = 0.00;
  12.  
  13.         for (int i = 0; i < num; i++) {
  14.             double grade = Double.parseDouble(console.nextLine());
  15.             if (grade >= 5.00) {
  16.                 top++;
  17.             }
  18.             if (grade >= 4 && grade <= 4.99) {
  19.                 betweenFour++;
  20.             }
  21.             if (grade >= 3 && grade <= 3.99) {
  22.                 betweenThree++;
  23.             }
  24.             if (grade < 3.00) {
  25.                 fail++;
  26.             }
  27.                 average += grade;
  28.         }
  29.  
  30.             System.out.printf("Top students: %.2f%s\n", ((double) top / (double) num * 100), "%");
  31.             System.out.printf("Between 4.00 and 4.99: %.2f%s\n", ((double) betweenFour / (double) num * 100), "%");
  32.             System.out.printf("Between 3.00 and 3.99: %.2f%s\n", ((double) betweenThree / (double) num * 100), "%");
  33.             System.out.printf("Fail: %.2f%s\n", ((double) fail / (double) num * 100), "%");
  34.             System.out.printf("Average: %.2f\n", (average / (double) num));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement