veronikaaa86

Cake

Feb 9th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04_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.  
  10.         int pieces = width * length;
  11.  
  12.         for (int i = 0; i <= 1000; i++) {
  13.             String takePieces = scanner.nextLine();
  14.  
  15.             if ("Stop".equalsIgnoreCase(takePieces)) {
  16.                 System.out.printf("%d pieces are left.", pieces);
  17.                 break;
  18.             } else {
  19.                 pieces -= Integer.valueOf(takePieces);
  20.                 if (pieces < 0) {
  21.                     System.out.printf("No more cake left! You need %d pieces more.", Math.abs(pieces));
  22.                     break;
  23.                 }
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment