Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package W05WhileLoop.Exercises;
- import java.util.Scanner;
- public class P07Moving {
- 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 availableSpace = width * length * height;
- //Прочитаме брой кашони докато не получим команда done
- String command = scanner.nextLine();
- //Правим while цикъл докато не получим команда done Или нямаме вече свободно пространство
- while (!command.equals("Done")){
- //Парсваме прочетения стринг към цяло число -> int
- int currentBoxes = Integer.parseInt(command);
- //Намаляме стойността на availableSpace
- availableSpace -= currentBoxes;
- if (availableSpace <= 0){
- System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(availableSpace));
- break;
- }
- command = scanner.nextLine();
- }
- //Проверяваме дали имаме останало свободно пространство
- if (availableSpace > 0){
- System.out.printf("%d Cubic meters left.", availableSpace);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement