Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Graduation2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String studentName = scanner.nextLine();
- int schoolClass = 1;
- double yearlyGradesSum = 0;
- int notPassed = 0;
- while (schoolClass <= 12 && notPassed < 2) {
- double grade = Double.parseDouble(scanner.nextLine());
- if (grade >= 4.00) {
- yearlyGradesSum+=grade;
- schoolClass++;
- } else {
- notPassed += 1;
- }
- }
- if (notPassed < 2) {
- double average = yearlyGradesSum / 12;
- System.out.printf("%s graduated. Average grade: %.2f", studentName, average);
- } else {
- System.out.printf("%s has been excluded at %d grade", studentName, schoolClass);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment