Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Autonomy {
- 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 volume = width * length * height;
- String cmd = scanner.nextLine();
- while (!cmd.equals("Done")) {
- int box = 0;
- try {
- box = Integer.parseInt(cmd);
- } catch (Exception e) {
- continue;
- }
- volume -= box;
- if (volume < 0) {
- System.out.printf("No more free space! You need %d Cubic meters more.", Math.abs(volume));
- break;
- }
- cmd = scanner.nextLine();
- }
- if (volume >= 0) {
- System.out.printf("%d Cubic meters left.", volume);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement