Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ExamPreparation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int badMarks = Integer.parseInt(scanner.nextLine());
- String problemName = scanner.nextLine();
- int grade = Integer.parseInt(scanner.nextLine());
- int failedAttempts = 0;
- int solvedProblemsCount = 0;
- double gradesSum = 0;
- String lastProblem = "";
- boolean isFailed = true;
- while (failedAttempts < badMarks) {
- problemName = scanner.nextLine();
- if ("Enough".equals(problemName)){
- isFailed = false;
- break;
- }else {
- isFailed = true;
- }
- grade = Integer.parseInt(scanner.nextLine());
- if (grade<=4){
- failedAttempts++;
- }gradesSum+=grade;
- solvedProblemsCount++;
- lastProblem = problemName;
- } if (isFailed){
- System.out.printf("You need a break, %d poor grades.", badMarks);
- } else {
- System.out.printf("Average score: %.2f%n", gradesSum/solvedProblemsCount);
- System.out.printf("Number of problems: %d%n", solvedProblemsCount);
- System.out.printf("Last problem: %s", lastProblem);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement