desislava_topuzakova

07. Water Overflow

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