Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package _05_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 height = Integer.parseInt(scanner.nextLine());
- int length = Integer.parseInt(scanner.nextLine());
- int apartmentSize = width * height * length;
- boolean isFreeSpaceLeft = true;
- String command = scanner.nextLine();
- while (!command.equals("Done")) {
- int boxes = Integer.parseInt(command);
- apartmentSize -= boxes;
- if (apartmentSize <= 0) {
- isFreeSpaceLeft = false;
- break;
- }
- command = scanner.nextLine();
- }
- if (!isFreeSpaceLeft) {
- System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(apartmentSize));
- } else {
- System.out.printf("%d Cubic meters left.", apartmentSize);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement