veronikaaa86

07. Moving

Feb 6th, 2022
597
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;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07Moving {
  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.  
  19. volume = volume - boxes;
  20.  
  21. if (volume <= 0) {
  22. break;
  23. }
  24.  
  25. input = scanner.nextLine();
  26. }
  27.  
  28. if (volume <= 0) {
  29. System.out.printf("No more free space! You need %d Cubic meters more.",
  30. Math.abs(volume));
  31. } else {
  32. System.out.printf("%d Cubic meters left.", volume);
  33. }
  34. }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment