Advertisement
veronikaaa86

07. Moving

Nov 28th, 2021
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. package WhileLoop.exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Moving {
  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 input = scanner.nextLine();
  16. while (!input.equals("Done")) {
  17. int boxes = Integer.parseInt(input);
  18. volume -= boxes;
  19. if (volume <= 0) {
  20. break;
  21. }
  22. input = scanner.nextLine();
  23. }
  24. if (volume <= 0) {
  25. System.out.printf("No more free space!" +
  26. " You need %d Cubic meters more.", Math.abs(volume));
  27. } else {
  28. System.out.printf("%d Cubic meters left.", volume);
  29. }
  30. }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement