Advertisement
psi_mmobile

Untitled

May 16th, 2022
571
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.  
  7.         int countPoorGrades = Integer.parseInt(scanner.nextLine());
  8.         int count = 0;
  9.         int totalSumGrades = 0;
  10.         double countProblems = 0;
  11.         String lastProblem = null;
  12.         boolean win =false;
  13.  
  14.         while (count < countPoorGrades) {
  15.             String problemName = scanner.nextLine();
  16.             if (problemName.equals("Enough")){
  17.                 win = true;
  18.                 break;
  19.             } else {
  20.                 lastProblem = problemName;
  21.                 countProblems++;
  22.             }
  23.            int currentGrade = Integer.parseInt(scanner.nextLine());
  24.             if(currentGrade <= 4){
  25.                 count++;
  26.             }
  27.             totalSumGrades += currentGrade;
  28.         }
  29.        if (win){
  30.            System.out.printf("Average score: %.2f\n",totalSumGrades / countProblems);
  31.            System.out.printf("Number of problems: %.0f\n",countProblems);
  32.            System.out.printf("Last problem: %s",lastProblem);
  33.        } else {
  34.            System.out.printf("You need a break, %d poor grades.",count);
  35.        }
  36.     }
  37. }
Advertisement
RAW Paste Data Copied
Advertisement