Guest User

Untitled

a guest
Apr 18th, 2018
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04_Autonomy {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int weight = Integer.parseInt(scanner.nextLine());
  8.         int length = Integer.parseInt(scanner.nextLine());
  9.         int height = Integer.parseInt(scanner.nextLine());
  10.         String input = scanner.nextLine();
  11.  
  12.  
  13.         boolean boxesleft = true;
  14.         int totalKm = weight * length * height;
  15.  
  16.         int totalBoxes = 0;
  17.         int km = totalKm;
  18.  
  19.         while (!input.equals("Done")){
  20.             int boxes = Integer.parseInt(input);
  21.             totalKm -= boxes;
  22.             totalBoxes += boxes;
  23.  
  24.             if (totalKm < 0){
  25.                 boxesleft = false;
  26.                 break;
  27.             }
  28.             input = scanner.nextLine();
  29.         }
  30.         if (boxesleft){
  31.             System.out.printf("%d Cubic meters left.", totalKm);
  32.         }else {
  33.             totalBoxes -= km;
  34.             System.out.printf("No more free space! You need %d Cubic meters more.", totalBoxes);
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment