Advertisement
silviasj

Moving2

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