Advertisement
Guest User

Untitled

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