desislava_topuzakova

Untitled

Feb 10th, 2022
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AverageGradeII {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String studentName = scanner.nextLine();
  8.  
  9. int grade = 1;
  10.  
  11. double sum = 0;
  12.  
  13. int repetion = 0;
  14.  
  15. boolean isExcluded = false;
  16.  
  17. while (grade <= 12) {
  18. double mark = Double.parseDouble(scanner.nextLine());
  19.  
  20. if (mark < 4) {
  21.  
  22. repetion++;
  23.  
  24.  
  25. if (repetion == 2) {
  26. isExcluded = true;
  27. System.out.printf("%s has been excluded at %d grade", studentName, grade);
  28. break;
  29. }
  30. continue;
  31. }
  32.  
  33. sum = sum + mark ;
  34.  
  35. grade ++;
  36.  
  37.  
  38. }
  39. double averageGrade = sum / 12;
  40.  
  41. if (!isExcluded) {
  42.  
  43. System.out.printf("%s graduated. Average grade: %.2f", studentName, averageGrade);
  44.  
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment