Advertisement
veronikaaa86

08. Graduation

Jun 10th, 2023
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package whileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P08Graduation {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String name = scanner.nextLine();
  10.  
  11.         double sum = 0;
  12.         int year = 1;
  13.         int countPoorGrade = 0;
  14.         while (year <= 12) {
  15.             if (countPoorGrade > 1) {
  16.                 break;
  17.             }
  18.  
  19.             double currentGrade = Double.parseDouble(scanner.nextLine());
  20.  
  21.             if (currentGrade < 4) {
  22.                 countPoorGrade++;
  23.                 continue;
  24.             }
  25.  
  26.             sum = sum + currentGrade;
  27.             year++;
  28.         }
  29.  
  30.         if (countPoorGrade < 1) {
  31.             double avgGrade = sum / 12;
  32.             System.out.printf("%s graduated. Average grade: %.2f%n", name, avgGrade);
  33.         } else {
  34.             System.out.printf("%s has been excluded at %d grade%n", name, year);
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement