Advertisement
Kancho

Container_With_Water

Feb 27th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Soft_Uni_Varibles {
  4. public static void main(String[] args) {
  5. Scanner key = new Scanner(System.in);
  6. System.out.print("Number: ");
  7. int num = Integer.parseInt(key.nextLine());
  8. int capacity = 255;
  9. int quantity = 0;
  10. for (int i = 0; i < num; i++) {
  11. System.out.printf("How many liters do you want to pour?: %n");
  12. int liters = Integer.parseInt(key.nextLine());
  13. quantity += liters;
  14.  
  15. if (quantity > capacity) {
  16. System.out.printf("Insufficient capacity! You poured %d liters.%n", quantity - liters);
  17. break;
  18. } else {
  19.  
  20.  
  21. System.out.printf("You poured %d liters.%n", quantity);
  22. }
  23.  
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement