Advertisement
veronikaaa86

08. Graduation pt.2

Apr 3rd, 2021
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package whileLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P08GraduationPt2 {
  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 excluded = 0;
  13. int count = 1;
  14. while (count <= 12) {
  15. if (excluded > 1) {
  16. break;
  17. }
  18.  
  19. double grade = Double.parseDouble(scanner.nextLine());
  20.  
  21. if (grade < 4.0) {
  22. excluded++;
  23. continue;
  24. }
  25.  
  26. sum += grade;
  27. count++;
  28. }
  29.  
  30. if (excluded > 1) {
  31. System.out.printf("%s has been excluded at %d grade%n", name, count);
  32. } else {
  33. System.out.printf("%s graduated. Average grade: %.2f", name, sum / 12);
  34. }
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement