Advertisement
GabrielHr00

07. Moving

Apr 7th, 2024
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package _05_WhileLoops;
  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 width = Integer.parseInt(scanner.nextLine());
  9.         int height = Integer.parseInt(scanner.nextLine());
  10.         int length = Integer.parseInt(scanner.nextLine());
  11.         int apartmentSize = width * height * length;
  12.  
  13.         boolean isFreeSpaceLeft = true;
  14.  
  15.         String command = scanner.nextLine();
  16.         while (!command.equals("Done")) {
  17.             int boxes = Integer.parseInt(command);
  18.             apartmentSize -= boxes;
  19.  
  20.             if (apartmentSize <= 0) {
  21.                 isFreeSpaceLeft = false;
  22.                 break;
  23.             }
  24.  
  25.             command = scanner.nextLine();
  26.         }
  27.  
  28.         if (!isFreeSpaceLeft) {
  29.             System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(apartmentSize));
  30.         } else {
  31.             System.out.printf("%d Cubic meters left.", apartmentSize);
  32.         }
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement