SHARE
TWEET

2

a guest May 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4.     public static void main(String[] args) {
  5.             Scanner scanner = new Scanner(System.in);
  6.             int numberBadGrades = Integer.parseInt(scanner.nextLine());
  7.             String lastProblem = "";
  8.             int numberOfProblems = 0;
  9.             double gradeSum=0.0;
  10.             int badGrades = 0;
  11.             String input = "";
  12.             int grade=0;
  13.             Boolean enough = false;
  14.  
  15.              while (badGrades<numberBadGrades ) {
  16.                  input = scanner.nextLine();
  17.                  if (input.equals("Enough")) {
  18.                      enough = true;
  19.                      break;
  20.                  } else {
  21.                      lastProblem = input;
  22.                      input = scanner.nextLine();
  23.                      grade = Integer.parseInt(input);
  24.                      if (grade<=4)
  25.                          badGrades++;
  26.  
  27.                      gradeSum = gradeSum + grade;
  28.                      numberOfProblems++;
  29.                  }
  30.              }
  31.              if (enough) {
  32.                  System.out.printf("Average score: %.2f%n" +
  33.                          "Number of problems: %d%n" +
  34.                          "Last problem: %s",(gradeSum/numberOfProblems),numberOfProblems,lastProblem );
  35.              }else
  36.                  System.out.printf("You need a break, %d poor grades.",badGrades);
  37.  
  38.              }
  39.  
  40.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top