Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- String x = sc.next();
- char t;
- boolean flag = true;
- ArrayStack<Character> w = new ArrayStack(x.length());
- for(int i=0;i<x.length();i++)
- {
- t = x.charAt(i);
- if(t=='('){
- w.push(t);
- }
- else if(w.isEmpty()) {
- System.out.println("Not Balanced");
- flag = false;
- break;
- }
- else{
- w.pop();
- }
- }
- if(flag)System.out.println("Balanced");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement