Advertisement
veronikaaa86

08. Graduation

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