Advertisement
marking2112

Moving

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