Advertisement
Lyubohd

Graduation

Feb 8th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 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 = 0;
  10.        
  11.         // 0 1 2 3 4 5 6 7 8 9 10 11 -> 12
  12.         // 1 2 3 4 5 6 7 8 9 10 11 12 -> 12
  13.        
  14.         while (counter < 12) {
  15.             double grade = Double.parseDouble(scan.nextLine());
  16.             if (grade >= 4.0) {
  17.                 grades += grade;
  18.                 counter++;
  19.             }
  20.         }
  21.        
  22.         double avgGrade = grades / 12;
  23.         System.out.printf("%s graduated. Average grade: %.2f", studentName, avgGrade);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement