Advertisement
CoineTre

9.Moving

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