myrdok123

P06Cake

Feb 5th, 2023
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package L05WhileLoop.Exercises;
  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.         String command = scanner.nextLine();
  12.  
  13.         int countAllPieces = width * length;
  14.  
  15.         while (!command.equals("STOP")){
  16.             int currentCountPieces = Integer.parseInt(command);
  17.             countAllPieces -= currentCountPieces;
  18.  
  19.             if (countAllPieces <= 0){
  20.                 System.out.printf("No more cake left! You need %d pieces more.", Math.abs(countAllPieces));
  21.                 break;
  22.             }
  23.  
  24.  
  25.  
  26.             command = scanner.nextLine();
  27.         }
  28.  
  29.  
  30.         if(countAllPieces > 0){
  31.             System.out.printf("%d pieces are left.", countAllPieces);
  32.         }
  33.  
  34.  
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment