Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Graduation2 {
- public static Scanner s = new Scanner(System.in);
- private static boolean excl = false;
- public static double testGrade(double getGrade, boolean flag) {
- if (getGrade >= 4) {
- return getGrade;
- } else {
- if (!flag) {
- getGrade = Double.parseDouble(s.nextLine());
- testGrade(getGrade, true);
- } else {
- excl = true;
- }
- return 0;
- }
- }
- public static void main(String[] args) {
- String name = s.nextLine();
- double grade = 0;
- double sum = 0;
- int gradeExcl = 0;
- while (!excl && gradeExcl<12) {
- gradeExcl++;
- grade = Double.parseDouble(s.nextLine());
- sum += testGrade(grade, false);
- }
- if (excl){
- System.out.println(name + " has been excluded at " + gradeExcl + " grade");
- }else{
- System.out.printf("%s graduated. Average grade: %.02f", name, sum/12);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement