Advertisement
Spocoman

01. Dishwasher

Aug 29th, 2024
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Dishwasher {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int detergentMl = Integer.parseInt(scanner.nextLine()) * 750;
  7.         int counter = 1, dishes = 0, pots = 0, charging;
  8.  
  9.         String input = "";
  10.         while (detergentMl >= 0 && !(input = scanner.nextLine()).equals("End")) {
  11.             charging = Integer.parseInt(input);
  12.  
  13.             if (counter % 3 != 0) {
  14.                 dishes += charging;
  15.                 detergentMl -= charging * 5;
  16.             } else {
  17.                 pots += charging;
  18.                 detergentMl -= charging * 15;
  19.             }
  20.             counter++;
  21.         }
  22.  
  23.         if (input.equals("End")) {
  24.             System.out.println("Detergent was enough!");
  25.             System.out.printf("%d dishes and %d pots were washed.\n", dishes, pots);
  26.             System.out.printf("Leftover detergent %d ml.", detergentMl);
  27.         } else {
  28.             System.out.printf("Not enough detergent, %d ml. more necessary!", Math.abs(detergentMl));
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement