Guest User

Untitled

a guest
Mar 7th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package Exam_03_September_2017;
  2.  
  3.         import java.util.Scanner;
  4.  
  5. public class Cake {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         int width = Integer.parseInt(input.nextLine());
  9.         int lenght = Integer.parseInt(input.nextLine());
  10.  
  11.         int pieces = width*lenght;
  12.         while (pieces>=0){
  13.             String  comand = input.nextLine();
  14.             if ("STOP".equals(comand)){
  15.                 System.out.printf("%d pieces are left.",pieces);
  16.             }else{
  17.                 int takenPiec = Integer.parseInt(comand);
  18.                 pieces-=takenPiec;
  19.             }
  20.         }
  21.         System.out.printf("No more cake left! You need %d pieces more.",Math.abs(pieces));
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment