Advertisement
desislava_topuzakova

07. Water Overflow

Jan 22nd, 2023
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. package DataTypes;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class WaterOverflow_07 {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. int capacity = 255;
  9. int currentLiters = 0;
  10. int n = Integer.parseInt(scanner.nextLine());
  11. for (int i = 1; i <= n; i++) {
  12. int pouredLiters = Integer.parseInt(scanner.nextLine());
  13. currentLiters += pouredLiters;
  14. if(currentLiters > capacity) {
  15. System.out.println("Insufficient capacity!");
  16. currentLiters -= pouredLiters;
  17. }
  18. }
  19.  
  20. System.out.println(currentLiters);
  21. }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement