Advertisement
veronikaaa86

06. Cake

Nov 28th, 2021
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 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 input = scanner.nextLine();
  15. while (!input.equals("STOP")) {
  16. int currentPieces = Integer.parseInt(input);
  17.  
  18. allPieces = allPieces - currentPieces;
  19. if (allPieces <= 0){
  20. break;
  21. }
  22.  
  23. input = scanner.nextLine();
  24. }
  25.  
  26. if (allPieces <= 0) {
  27. System.out.printf("No more cake left! You need %d pieces more.", Math.abs(allPieces));
  28. } else {
  29. System.out.printf("%d pieces are left.", allPieces);
  30. }
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement