Advertisement
Lyubohd

Graduation pt.2

Feb 8th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String studentName = scan.nextLine();
  8.         double grades = 0;
  9.         int counter = 1;
  10.         int notPass = 0;
  11.  
  12.         // 0 1 2 3 4 5 6 7 8 9 10 11 -> 12
  13.         // 1 2 3 4 5 6 7 8 9 10 11 12 -> 12
  14.  
  15.         while (counter <= 12) {
  16.             double grade = Double.parseDouble(scan.nextLine());
  17.             if (grade >= 4.0) {
  18.                 grades += grade;
  19.                 counter++;
  20.             } else {
  21.                 notPass++;
  22.             }
  23.  
  24.             if (notPass > 1) {
  25.                 break;
  26.             }
  27.         }
  28.  
  29.         if (notPass > 1) {
  30.             System.out.printf("%s has been excluded at %d grade", studentName, counter);
  31.         } else {
  32.             double avgGrade = grades / 12;
  33.             System.out.printf("%s graduated. Average grade: %.2f", studentName, avgGrade);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement