Advertisement
Krassi_Daskalova

Cake1

Feb 10th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Cake1 {
  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. String command = scanner.nextLine();
  10.  
  11. int pieces = width * length;
  12.  
  13. while (!command.equals("STOP")) {
  14. int takenPieces = Integer.parseInt(command);
  15. pieces = pieces - takenPieces;
  16.  
  17. if (pieces < 0) {
  18. System.out.printf("No more cake left! You need %d pieces more.", Math.abs(pieces));
  19. break;
  20. }
  21. command = scanner.nextLine();
  22. }
  23. if (command.equals("STOP")) {
  24. System.out.printf("%d pieces are left.",pieces);
  25. }
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement