Advertisement
veronikaaa86

09. Moving

Apr 3rd, 2021
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package whileLoops;
  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. int boxesSum = 0;
  18. while (!input.equals("Done")){
  19. int boxes = Integer.parseInt(input);
  20.  
  21. boxesSum += boxes;
  22.  
  23. if (boxesSum >= volumeHouse){
  24. break;
  25. }
  26.  
  27. input = scanner.nextLine();
  28. }
  29.  
  30. int diff = Math.abs(boxesSum - volumeHouse);
  31. if (boxesSum >= volumeHouse) {
  32. System.out.printf("No more free space! You need %d Cubic meters more.", diff);
  33. } else {
  34. System.out.printf("%d Cubic meters left.", diff);
  35. }
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement