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 badGrades = Integer.parseInt(scanner.nextLine());
- String task = "", lastProblem = "";
- int badGradesCounter = 0, tasksCount = 0;
- double sumGrades = 0, grade = 0;
- while (!(task = scanner.nextLine()).equals("Enough")) {
- grade = Double.parseDouble(scanner.nextLine());
- sumGrades += grade;
- tasksCount++;
- if (grade <= 4) {
- badGradesCounter++;
- if (badGradesCounter == badGrades) {
- System.out.printf("You need a break, %d poor grades.\n", badGrades);
- break;
- }
- }
- lastProblem = task;
- }
- if (task.equals("Enough")) {
- System.out.printf("Average score: %.2f\n", sumGrades / tasksCount);
- System.out.printf("Number of problems: %d\n", tasksCount);
- System.out.printf("Last problem: %s\n", lastProblem);
- }
- }
- }
- ИЛИ:
- 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 task = "", lastProblem = "";
- int badGradesCounter = 0, tasksCount = 0;
- double sumGrades = 0, grade = 0;
- while (badGradesCounter != badGrades
- &&!(task = scanner.nextLine()).equals("Enough")) {
- grade = Double.parseDouble(scanner.nextLine());
- if (grade <= 4) {
- badGradesCounter++;
- }
- sumGrades += grade;
- lastProblem = task;
- tasksCount++;
- }
- if (badGradesCounter == badGrades) {
- System.out.printf("You need a break, %d poor grades.\n", badGrades);
- } else {
- System.out.printf("Average score: %.2f\n", sumGrades / tasksCount);
- System.out.printf("Number of problems: %d\n", tasksCount);
- System.out.printf("Last problem: %s\n", lastProblem);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement