Advertisement
veronikaaa86

Cake1

Nov 1st, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package Exam3September2017;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04_Cake {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int width = Integer.parseInt(scanner.nextLine());
  10.         int length = Integer.parseInt(scanner.nextLine());
  11.  
  12.         int pieces = width * length;
  13.  
  14.         for (int i = 0; i <= 1000; i++) {
  15.             String takePieces = scanner.nextLine();
  16.  
  17.             if ("Stop".equalsIgnoreCase(takePieces)) {
  18.                 System.out.printf("%d pieces are left.", pieces);
  19.                 break;
  20.             } else {
  21.                 pieces -= Integer.valueOf(takePieces);
  22.                 if (pieces < 0) {
  23.                     System.out.printf("No more cake left! You need %d pieces more.", Math.abs(pieces));
  24.                     break;
  25.                 }
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement