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