Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. static Scanner sc = new Scanner(System.in);
  2. public static void main(String[] args) {
  3. String x = sc.next();
  4. char t;
  5. boolean flag = true;
  6. ArrayStack<Character> w = new ArrayStack(x.length());
  7. for(int i=0;i<x.length();i++)
  8. {
  9. t = x.charAt(i);
  10. if(t=='('){
  11. w.push(t);
  12. }
  13. else if(w.isEmpty()) {
  14. System.out.println("Not Balanced");
  15. flag = false;
  16. break;
  17. }
  18. else{
  19. w.pop();
  20. }
  21. }
  22. if(flag)System.out.println("Balanced");
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement