Advertisement
Lyubohd

01. Dishwasher

Apr 23rd, 2020
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DemLoop {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int BottlesDetergent = Integer.parseInt(scanner.nextLine());
  8.         int plates = 0;
  9.         int pots = 0;
  10.         int amoundOfDetergentOneBottle = 750;
  11.         int amoundOfDetergent;
  12.         int counterSpin = 0;
  13.         int dishes = 0;
  14.         amoundOfDetergent = BottlesDetergent * 750;//
  15.  
  16.         String input = scanner.nextLine();
  17.  
  18.         while (!input.equals("End")) {
  19.             // pishe se v chikula
  20.             counterSpin++;
  21.             dishes = Integer.parseInt(input);
  22.  
  23.             if (counterSpin % 3 == 0) {//(counterSpin == 3)
  24.                 pots += dishes;
  25.                 amoundOfDetergent -= 15 * dishes;
  26.             } else {
  27.                 plates += dishes;
  28.                 amoundOfDetergent -= 5 * dishes;
  29.             }
  30.  
  31.             if (amoundOfDetergent < 0) {
  32.                 break;
  33.             }
  34.  
  35.             input = scanner.nextLine();
  36.         }
  37.  
  38.         if (amoundOfDetergent < 0) {
  39.             System.out.printf("Not enough detergent, %d ml. more necessary!%n", Math.abs(amoundOfDetergent));
  40.         } else {
  41.             System.out.println("Detergent was enough!");
  42.             System.out.printf("%d dishes and %d pots were washed.%n", plates, pots);
  43.             System.out.printf("Leftover detergent %d ml.%n", amoundOfDetergent);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement