Advertisement
damesova

Cake [Mimi][Basics]

Apr 29th, 2019
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 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.  
  7.         int width = Integer.parseInt(scanner.nextLine());
  8.         int length = Integer.parseInt(scanner.nextLine());
  9.         int cakePiece = width * length;
  10.         int getPiece = 0;
  11.         String command = "";
  12.  
  13.         while (cakePiece >= 0) {
  14.             command = scanner.nextLine();
  15.  
  16.             if (command.equals("STOP")) {
  17.                 System.out.printf("%d pieces are left.", cakePiece);
  18.                 break;
  19.             } else {
  20.                 getPiece = Integer.parseInt(command);
  21.                 cakePiece = cakePiece - getPiece;
  22.             }
  23.         }
  24.  
  25.         if (!command.equals("STOP"))
  26.         System.out.printf("No more cake left! You need %d pieces more.", Math.abs(cakePiece));
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement