Advertisement
myrdok123

07. Moving

Mar 10th, 2024
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. package WhileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Moving {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int width = Integer.parseInt(scanner.nextLine());
  11.         int length = Integer.parseInt(scanner.nextLine());
  12.         int height = Integer.parseInt(scanner.nextLine());
  13.  
  14.         int availableSpace = width * length * height;
  15.  
  16.         String command = scanner.nextLine();
  17.  
  18.         while (!command.equals("Done")){
  19.  
  20.             int currentBoxes = Integer.parseInt(command);
  21.  
  22.             availableSpace -= currentBoxes;
  23.  
  24.             if(availableSpace <= 0){
  25.                 System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(availableSpace));
  26.                 break;
  27.             }
  28.  
  29.  
  30.  
  31.             command = scanner.nextLine();
  32.         }
  33.  
  34.         if(availableSpace > 0){
  35.             System.out.printf("%d Cubic meters left.", availableSpace);
  36.         }
  37.  
  38.  
  39.  
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement