desislava_topuzakova

09. Moving

Jul 6th, 2021
1,386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Moving {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int freeHight = Integer.parseInt(scan.nextLine());
  7.         int freeWidth = Integer.parseInt(scan.nextLine());
  8.         int freeLength = Integer.parseInt(scan.nextLine());
  9.         String input = scan.nextLine();
  10.  
  11.         int allBoxVolume = 0;
  12.         int freeVolume = freeHight * freeWidth * freeLength;
  13.         int freeSpaceLeft = freeVolume - allBoxVolume;
  14.  
  15.  
  16.         while (!input.equals("Done")) {
  17.  
  18.             int boxCount = Integer.parseInt(input);
  19.             allBoxVolume += boxCount * 1;
  20.             freeSpaceLeft = freeVolume - allBoxVolume;
  21.  
  22.             if (freeSpaceLeft <= 0) {              
  23.                 System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(freeSpaceLeft));
  24.                 break;
  25.             }
  26.             input = scan.nextLine();
  27.         }
  28.         if (freeSpaceLeft <=0) {
  29.         }else {
  30.             System.out.printf("%d Cubic meters left.", Math.abs(freeSpaceLeft));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment