Advertisement
Guest User

Grades

a guest
Mar 30th, 2020
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 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.  
  7.         int students = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int moreThan5 = 0;
  10.         int moreThan4 = 0;
  11.         int moreThan3 = 0;
  12.         int lessThan3 = 0;
  13.  
  14.         double markResult = 0;
  15.  
  16.         for (int i = 1; i <= students; i++) {
  17.             double mark = Double.parseDouble(scanner.nextLine());
  18.             if (mark >= 5.00) {
  19.                 moreThan5++;
  20.             } else if (mark >= 4.00) {
  21.                 moreThan4++;
  22.             } else if (mark >= 3.00) {
  23.                 moreThan3++;
  24.             } else {
  25.                 lessThan3++;
  26.             }
  27.             markResult += mark;
  28.         }
  29.  
  30.         double topStudents = 100.0 * moreThan5 /  students;
  31.         double fourStudents = 100.0 * moreThan4 /  students;
  32.         double threeStudents = 100.0 * moreThan3 / students;
  33.         double twoStudents = 100.0 * lessThan3 /  students;
  34.  
  35.         System.out.printf("Top students: %.2f%%%n", topStudents);
  36.         System.out.printf("Between 4.00 and 4.99: %.2f%%%n", fourStudents);
  37.         System.out.printf("Between 3.00 and 3.99: %.2f%%%n", threeStudents);
  38.         System.out.printf("Fail: %.2f%%%n", twoStudents);
  39.         System.out.printf("Average: %.2f", markResult / students);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement