Advertisement
Spocoman

04. Grades

Aug 28th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Grades {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int students = Integer.parseInt(scanner.nextLine());
  7.         double grade3 = 0, grade4 = 0, grade5 = 0, grade6 = 0, gradeSum = 0;
  8.  
  9.         for (int i = 0; i < students; i++) {
  10.             double grade = Double.parseDouble(scanner.nextLine());
  11.             if (grade >= 5) {
  12.                 grade6++;
  13.             } else if (grade >= 4) {
  14.                 grade5++;
  15.             } else if (grade >= 3) {
  16.                 grade4++;
  17.             } else if (grade >= 2) {
  18.                 grade3++;
  19.             }
  20.             gradeSum += grade;
  21.         }
  22.  
  23.         System.out.printf("Top students: %.2f%%\n", grade6 / students * 100);
  24.         System.out.printf("Between 4.00 and 4.99: %.2f%%\n", grade5 / students * 100);
  25.         System.out.printf("Between 3.00 and 3.99: %.2f%%\n", grade4 / students * 100);
  26.         System.out.printf("Fail: %.2f%%\n", grade3 / students * 100);
  27.         System.out.printf("Average: %.2f\n", gradeSum / students);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement