Advertisement
veronikaaa86

06. Cake

Feb 6th, 2022
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package whileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06Cake {
  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 allPieces = width * length;
  13.  
  14. String command = scanner.nextLine();
  15. while (!command.equals("STOP")) {
  16. int currentPieces = Integer.parseInt(command);
  17.  
  18. allPieces = allPieces - currentPieces;
  19. if (allPieces < 0) {
  20. break;
  21. }
  22.  
  23. command = scanner.nextLine();
  24. }
  25.  
  26. if (allPieces <= 0) {
  27. System.out.printf("No more cake left! You need %d pieces more.",
  28. Math.abs(allPieces));
  29. } else {
  30. System.out.printf("%d pieces are left.", allPieces);
  31. }
  32. }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement