Advertisement
veronikaaa86

08. Graduation pt.2

Jun 5th, 2021
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package whileLoop;
  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. int count = 1;
  12. double sum = 0;
  13. int excluded = 0;
  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 = sum + grade;
  27.  
  28. count++;
  29. }
  30.  
  31. if (excluded > 1){
  32. System.out.printf("%s has been excluded at %d grade", name, count);
  33. } else {
  34. System.out.printf("%s graduated. Average grade: %.2f", name, sum / 12);
  35. }
  36.  
  37. }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement