Advertisement
veronikaaa86

08. Graduation

Jun 4th, 2022
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 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 poorGradeCount = 0;
  14. while (year <= 12) {
  15. if (poorGradeCount == 2) {
  16. break;
  17. }
  18. double currentGrade = Double.parseDouble(scanner.nextLine());
  19.  
  20. if (currentGrade < 4){
  21. poorGradeCount++;
  22. continue;
  23. }
  24. sum = sum + currentGrade;
  25.  
  26. year++;
  27. }
  28.  
  29. if (poorGradeCount == 2) {
  30. System.out.printf("%s has been excluded at %d grade", name, year);
  31. } else {
  32. double avgGrade = sum / (year - 1);
  33. System.out.printf("%s graduated. Average grade: %.2f", name, avgGrade);
  34. }
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement