Advertisement
IvoSavov

Cake

May 18th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int widthOfCake = Integer.parseInt(scanner.nextLine());
  7.         int lengthOfCake = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int leftPieces = widthOfCake * lengthOfCake;
  10.         String input = scanner.nextLine();
  11.  
  12.         while(!input.equals("STOP")) {
  13.             leftPieces -= Integer.parseInt(input);
  14.  
  15.             if (leftPieces <= 0) {
  16.                 break;
  17.             }
  18.  
  19.             input = scanner.nextLine();
  20.         }
  21.  
  22.         if(leftPieces >= 0) {
  23.             System.out.printf("%d pieces are left.", leftPieces);
  24.         } else {
  25.             System.out.printf("No more cake left! You need %d pieces more.", Math.abs(leftPieces));
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement