I write a java code to write all combinations of bit string with length N" . this code print all combination but I want to have all combination with exactly N length and "H" 1's.
like N=4 & H=2 => 0011,0101,0110,1100,1010,1001
public void print(int n, char[] k, char[] A) {
if (n <= 0) {
System.out.print(String.valueOf(A) + " ");
} else {
for (int i = 0; i < k.length; i++) {
A[n - 1] = k[i];
print(n - 1, k, A);
}
}
}
public static void main(String[] args) {
String k = "01";
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
int n = in.nextInt();
MiniProject i = new MiniProject();
i.print(n, k.toCharArray(), new char[n]);
}