Advertisement
desislava_topuzakova

07. Water Overflow

May 27th, 2022
1,240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement