grach

05. Exam Preparation exam 09 May 2020

May 15th, 2020
1,834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int students = Integer.parseInt(scan.nextLine());
  8.  
  9.         int sumTask = 0;
  10.         //  int sumEnergy = 0;
  11.         int question = 0;
  12.  
  13.         int task = Integer.parseInt(scan.nextLine());
  14.         int energy = Integer.parseInt(scan.nextLine());
  15.         int sumQuestion = 0;
  16.         boolean trainer = false;
  17.  
  18.         while (students >= 10) {
  19.  
  20.             sumTask += task;
  21.             energy += task * 2;
  22.             students -= 5;
  23.  
  24.             question = students * 2;
  25.             energy -= 3 * question;
  26.             // question++;
  27.             sumQuestion += question;
  28.             if (energy <= 0) {
  29.                 trainer = true;
  30.                 break;
  31.             }
  32.             int newStudents = students / 10;
  33.             students = students + newStudents;
  34.         }
  35.  
  36.         if (trainer == false) {
  37.             System.out.println("The students are too few!");
  38.             System.out.printf("Problems solved: %d", sumTask);
  39.         } else {
  40.             System.out.println("The trainer is too tired!");
  41.             System.out.printf("Questions answered: %d", sumQuestion);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment