Advertisement
Spocoman

07. Water Overflow

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