Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Y03examPreparation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int maxPoorGrades = Integer.parseInt(scanner.nextLine());
- int counterPoorGrades = 0;
- int counterAlltask = 0;
- double averageScore = 0;
- int scoreAllGrades = 0;
- String lastProblem = "";
- while (maxPoorGrades > counterPoorGrades){
- String task = scanner.nextLine();
- if (task.equals("Enough")){
- break;
- }
- int currentGrade = Integer.parseInt(scanner.nextLine());
- if (currentGrade <= 4){
- counterPoorGrades++;
- }
- counterAlltask++;
- scoreAllGrades += currentGrade;
- lastProblem = task;
- }
- averageScore = (scoreAllGrades * 1.0) / counterAlltask;
- if (counterPoorGrades == maxPoorGrades){
- System.out.printf("You need a break, %d poor grades.",counterPoorGrades);
- }
- else {
- System.out.printf("Average score: %.2f%n", averageScore);
- System.out.printf("Number of problems: %d%n", counterAlltask);
- System.out.printf("Last problem: %s", lastProblem);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment