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 badGrades = Integer.parseInt(scanner.nextLine());
- String name = scanner.nextLine();
- int sum = 0;
- int countBadGrades = 0;
- int tasks = 0;
- String last = "";
- while (!name.equals("Enough")) {
- int grade = Integer.parseInt(scanner.nextLine());
- sum += grade;
- tasks++;
- if (grade <= 4) {
- countBadGrades++;
- }
- if (badGrades == countBadGrades) {
- System.out.printf("You need a break, %d poor grades.", countBadGrades);
- break;
- }
- last = name;
- name = scanner.nextLine();
- if (name.equals("Enough")) {
- double average = sum * 1.0 / tasks;
- System.out.printf("Average score: %.2f%n", average);
- System.out.printf("Number of problems: %d%n", tasks);
- System.out.printf("Last problem: %s ", last);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment