Advertisement
veronikaaa86

09. Moving

Jun 5th, 2021
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package whileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P09Moving {
  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 volumeHouse = width * length * height;
  14.  
  15. String input = scanner.nextLine();
  16.  
  17. boolean isFull = false;
  18. int sumBoxes = 0;
  19. while (!input.equals("Done")) {
  20. int boxes = Integer.parseInt(input);
  21.  
  22. sumBoxes = sumBoxes + boxes;
  23.  
  24. if (sumBoxes > volumeHouse) {
  25. isFull = true;
  26. break;
  27. }
  28.  
  29. input = scanner.nextLine();
  30. }
  31.  
  32. int diff = Math.abs(volumeHouse - sumBoxes);
  33. if (isFull) {
  34. System.out.printf("No more free space! You need %d Cubic meters more.", diff);
  35. } else {
  36. System.out.printf("%d Cubic meters left.", diff);
  37. }
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement