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 height = Integer.parseInt(scanner.nextLine());
- int length = Integer.parseInt(scanner.nextLine());
- // calc volume of the house
- int volume = width * height * length;
- // read first command
- String command = scanner.nextLine();
- while(!command.equals("Done")) {
- // convert the count of boxes to int
- int boxes = Integer.parseInt(command);
- // reduce overall place
- volume = volume - boxes;
- // check for still available space
- if(volume <= 0) {
- break;
- }
- command = scanner.nextLine();
- }
- // check if all boxes are in the house
- if(volume <= 0) {
- System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(volume));
- } else {
- System.out.printf("%d Cubic meters left.", volume);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement