- Backtracking, Combinatorial, Recursion, Strings

Print all Balanced Brackets Strings that can be formed by replacing wild card ‘?’

import java.io.*;import java.util.*;class Main {            static void print(char ch[])    {        for (Character c : ch) {            System.out.print(c);        }        System.out.println();    }            static boolean check(char ch[])    {                Stack S = new Stack();                        if (ch[0] == ‘)’) {            return false;        }                for (int i = 0; i < ch.length; i++) {                                    if (ch[i] == '(') {                S.add('(');            }                        else {                                                                if (S.size() == 0)                    return false;                                                else                    S.pop();            }        }                        if (S.size() == 0)            return true;                        else            return false;    }            static void count(char ch[], int index)    {                if (index == ch.length) {                                    if (check(ch)) {                                                print(ch);            }            return;        }        if (ch[index] == '?') {                        ch[index] = '(';            count(ch, index + 1);                        ch[index] = ')';            count(ch, index + 1);                        ch[index] = '?';        }        else {                                                count(ch, index + 1);        }    }        public static void main(String[] args)    {        String m = "????";        char ch[] = m.toCharArray();                count(ch, 0);    }}