Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int bottlesOfDetergent = Integer.parseInt(scanner.nextLine());
- int sumPlates = 0;
- int sumPots = 0;
- int count = 0;
- int amountOfDitergent = bottlesOfDetergent * 750;
- String command = scanner.nextLine();
- while (!command.equals("End")) {
- int numberOfDishes = Integer.parseInt(command);
- int detergentUsed = 0;
- count++;
- if (count % 3 == 0){
- detergentUsed = numberOfDishes * 15;
- sumPots += numberOfDishes;
- }else {
- detergentUsed = numberOfDishes * 5;
- sumPlates += numberOfDishes;
- }
- amountOfDitergent -= detergentUsed;
- if (amountOfDitergent < 0) {
- break;
- }
- command = scanner.nextLine();
- }
- if (amountOfDitergent >= 0) {
- System.out.println("Detergent was enough!");
- System.out.printf("%d dishes and %d pots were washed.%n", sumPlates, sumPots);
- System.out.printf("Leftover detergent %d ml.", amountOfDitergent);
- }else {
- System.out.printf("Not enough detergent, %d ml. more necessary!", Math.abs(amountOfDitergent));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment