Advertisement
CoineTre

06.Cake

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