Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S5_WhileLoops;
- import java.util.Scanner;
- public class Moving {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int width = Integer.parseInt(scanner.nextLine());
- int length = Integer.parseInt(scanner.nextLine());
- int height = Integer.parseInt(scanner.nextLine());
- int volumeRoom = width * length * height;
- boolean isFreeSpace = true;
- String command = scanner.nextLine();
- while (!command.equals("Done")) {
- int boxes = Integer.parseInt(command);
- volumeRoom -= boxes;
- if (volumeRoom <= 0) {
- isFreeSpace = false;
- break;
- }
- command = scanner.nextLine();
- }
- if(!isFreeSpace) {
- System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(volumeRoom));
- } else {
- System.out.printf("%d Cubic meters left.", volumeRoom);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement