Krassi_Daskalova

Moving1

Feb 10th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Moving1 {
  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 command = scanner.nextLine();
  11.  
  12. int room = width * length * height;
  13. boolean isThereEnoughSpace = true;
  14.  
  15. while (!"Done".equals(command)){
  16. int boxes = Integer.parseInt(command);
  17. room = room - boxes;
  18.  
  19. if(room < 0)
  20. {
  21. isThereEnoughSpace = false;
  22. break;
  23. }
  24. command = scanner.nextLine();
  25. }
  26. if(isThereEnoughSpace){
  27. System.out.printf("%d Cubic meters left.", room);
  28. } else{
  29. System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(room));
  30. }
  31.  
  32. }
  33. }
Add Comment
Please, Sign In to add comment