desislava_topuzakova

07. Water Overflow

Jan 23rd, 2021
681
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DataTypes;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class WaterOverflow_07 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int capacity = 255;
  10.         int n = Integer.parseInt(scanner.nextLine());
  11.  
  12.         for (int i = 0; i < n; i++) {
  13.             int pourLiters = Integer.parseInt(scanner.nextLine());
  14.             capacity -= pourLiters;
  15.             if(capacity < 0) {
  16.                 System.out.println("Insufficient capacity!");
  17.                 capacity += pourLiters;
  18.             }
  19.         }
  20.  
  21.         System.out.println(255 - capacity);
  22.     }
  23. }
  24.  
RAW Paste Data