Advertisement
Sim0o0na

Untitled

Mar 28th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Autonomy {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int width = Integer.parseInt(scanner.nextLine());
  10. int length = Integer.parseInt(scanner.nextLine());
  11. int height = Integer.parseInt(scanner.nextLine());
  12.  
  13. int volume = width * length * height;
  14.  
  15. String cmd = scanner.nextLine();
  16. while (!cmd.equals("Done")) {
  17. int box = 0;
  18. try {
  19. box = Integer.parseInt(cmd);
  20. } catch (Exception e) {
  21. continue;
  22. }
  23. volume -= box;
  24. if (volume < 0) {
  25. System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(volume));
  26. break;
  27. }
  28. cmd = scanner.nextLine();
  29. }
  30.  
  31. if (volume >= 0) {
  32. System.out.printf("%d Cubic meters left.", volume);
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement