Helena12

Moving (SoftUni Exam)

Nov 4th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 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 roomVolume = w * l * h;
  12.         int boxesVolume = 0;
  13.  
  14.         while (boxesVolume <= roomVolume) {
  15.             String command = scanner.nextLine();
  16.  
  17.             if(command.equalsIgnoreCase("done")) {
  18.                 break;
  19.             }
  20.  
  21.             int currentBoxesCount = Integer.parseInt(command);
  22.             boxesVolume += currentBoxesCount;
  23.         }
  24.  
  25.         int volumeDifference = roomVolume - boxesVolume;
  26.  
  27.         if (volumeDifference >= 0) {
  28.             System.out.printf("%d Cubic meters left.", volumeDifference);
  29.         } else {
  30.             System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(volumeDifference));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment