silviasj

Moving

Apr 4th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 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 width = Integer.parseInt(scan.nextLine());
  7.         int length = Integer.parseInt(scan.nextLine());
  8.         int height = Integer.parseInt(scan.nextLine());
  9.         String bag = scan.nextLine();
  10.         int bagSpace = 0;
  11.         int freeSpace = width * length * height;
  12.         while (!bag.equals("Done")) {
  13.             int count = Integer.parseInt(bag);
  14.             bagSpace += count;
  15.             if (freeSpace <= bagSpace) {
  16.                 int need = bagSpace - freeSpace;
  17.                 System.out.printf("No more free space! You need %d Cubic meters more.", need);
  18.                 break;
  19.             }
  20.             bag = scan.nextLine();
  21.         }
  22.         if (bag.equals("Done")) {
  23.             int left = freeSpace - bagSpace;
  24.             System.out.printf("%d Cubic meters left.", left);
  25.         }
  26.     }
  27. }
Add Comment
Please, Sign In to add comment