Advertisement
drago68

Untitled

Oct 1st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class BalancedBrackets {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. int n = Integer.parseInt(scanner.nextLine());
  12.  
  13. int count=0;
  14. int count1=0;
  15. for (int i = 0; i < n; i++) {
  16. String wordone = scanner.nextLine();
  17. for (int j = 0; j < wordone.length(); j++) {
  18. char c = wordone.charAt(j);
  19. if (c=='('){
  20. count++;
  21. }
  22. if (c==')'){
  23. count1++;
  24. }
  25. }
  26. }
  27. if (count==count1){
  28. System.out.println("BALANCED");
  29. }else {
  30. System.out.println("UNBALANCED");
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement