Advertisement
desislava_topuzakova

08. Graduation

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