I'm writing a program to generate all possible combination of a string 1*0* by replacing * by 0 or 1. This program only gives 3 values and is missing one value. Can someone help me find out the issue in this code?
For input 1*0*, this solution only gives 3 results: 1000, 1001, 1101. The missing value is 1100. Thanks.
public class TestClass{
public static void generateComb (char[] ch, int index) {
if (index == ch.length)
{
System.out.println (ch);
return;
}
if (ch[index]=='*'){
ch[index] = '0';
generateComb (ch, index+1);
ch[index] = '1';
generateComb (ch, index+1);
}
else {
generateComb (ch, index+1);
}
}
public static void main (String[] args) throws Exception {
char[] chtest = {'1', '*', '0', '*'};
generateComb(chtest, 0);
}
}