yovkovbpfps

While Loop Moving

Apr 3rd, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Moving {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int width = Integer.parseInt(scanner.nextLine());
  8. int length = Integer.parseInt(scanner.nextLine());
  9. int heigth = Integer.parseInt(scanner.nextLine());
  10.  
  11. int roomVolume = width * length * heigth;
  12.  
  13. String input = scanner.nextLine();
  14.  
  15. while (!"Done".equals(input)){
  16. int boxCount = Integer.parseInt(input);
  17.  
  18. roomVolume = roomVolume - boxCount;
  19.  
  20. if (roomVolume < 0){
  21. break;
  22. }
  23. input = scanner.nextLine();
  24. }
  25. if (roomVolume >= 0) {
  26. System.out.printf("%d Cubic meters left.",roomVolume);
  27. } else {
  28. System.out.printf("No more free space! You need %d Cubic meters more.",Math.abs(roomVolume));
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment