myrdok123

P07Moving

Feb 5th, 2023
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package L05WhileLoop.Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07Moving {
  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.         String command = scanner.nextLine();
  14.         int availableSpace = width * length * height;
  15.  
  16.  
  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.             command = scanner.nextLine();
  31.         }
  32.  
  33.         if(availableSpace > 0){
  34.             System.out.printf("%d Cubic meters left.", availableSpace);
  35.  
  36.         }
  37.  
  38.  
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment