Advertisement
GabrielHr00

Moving

Nov 27th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package S5_WhileLoops;
  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. int width = Integer.parseInt(scanner.nextLine());
  9. int height = Integer.parseInt(scanner.nextLine());
  10. int length = Integer.parseInt(scanner.nextLine());
  11.  
  12. // calc volume of the house
  13. int volume = width * height * length;
  14.  
  15. // read first command
  16. String command = scanner.nextLine();
  17. while(!command.equals("Done")) {
  18. // convert the count of boxes to int
  19. int boxes = Integer.parseInt(command);
  20. // reduce overall place
  21. volume = volume - boxes;
  22.  
  23. // check for still available space
  24. if(volume <= 0) {
  25. break;
  26. }
  27. command = scanner.nextLine();
  28. }
  29.  
  30.  
  31. // check if all boxes are in the house
  32. if(volume <= 0) {
  33. System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(volume));
  34. } else {
  35. System.out.printf("%d Cubic meters left.", volume);
  36. }
  37.  
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement