Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
995 B
2
Indexable
Never
package WhileLoops;

import java.util.Scanner;

public class GraduationVers2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String name = scan.nextLine();

        double gradeTotal = 0;
        double gradeAvg = 0;
        int fail = 0;

        int i = 0;   //i e koi klas e uchenika
        while (i <= 12) {
            double grade = Double.parseDouble(scan.nextLine());
            if (grade < 4) {
                fail++;

            }
            if (fail > 1) {   // ako ima niska ocenka poveche ot edin put togava se izpulnqva komandata za skusvane :
                System.out.printf("%s has been excluded at %d grade", name, i);
                break;
            }
            gradeTotal = gradeTotal + grade;
            i++;
            if (i == 12) {
                gradeAvg = gradeTotal / 12;
                System.out.printf("%s graduated. Average grade: %.2f", name, gradeAvg); break;
            }
        }
    }
}