Advertisement
GabrielHr00

07. Moving

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