Advertisement
Spocoman

08. Graduation

Aug 28th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Graduation {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String name = scanner.nextLine();
  7.         int breakPoint = 0, counter = 1;
  8.         double sumGrades = 0;
  9.  
  10.         while (true) {
  11.             double grade = Double.parseDouble(scanner.nextLine());
  12.  
  13.             if (grade >= 4) {
  14.                 sumGrades += grade;
  15.                 counter++;
  16.             } else {
  17.                 breakPoint++;
  18.             }
  19.  
  20.             if (counter == 13) {
  21.                 System.out.printf("%s graduated. Average grade: %.2f\n", name, sumGrades / 12);
  22.                 break;
  23.             }
  24.  
  25.             if (breakPoint == 2) {
  26.                 System.out.printf("%s has been excluded at %d grade", name, counter);
  27.                 break;
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement