Advertisement
Ivelin_Arsov

Water Overflow

May 29th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import org.w3c.dom.ls.LSOutput;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class WaterOverflow {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int n = Integer.parseInt(scan.nextLine());
  9.         int sumOfWater = 0;
  10.         int capacity = 255;
  11.         for (int i = 1; i <= n; i++) {
  12.             int liters = Integer.parseInt(scan.nextLine());
  13.             if (sumOfWater + liters > capacity) {
  14.                 System.out.println("Insufficient capacity!");
  15.             } else {
  16.                 sumOfWater += liters;
  17.             }
  18.         }
  19.         System.out.println(sumOfWater);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement