Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active May 28, 2018 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/2b25850befad09ea81b2 to your computer and use it in GitHub Desktop.
Save thmain/2b25850befad09ea81b2 to your computer and use it in GitHub Desktop.
import java.util.*;
public class NbitsStrings {
int[] arrA;
public NbitsStrings(int n) {
arrA = new int[n];
}
public void nBits(int n) {
if (n <= 0) {
System.out.println(Arrays.toString(arrA));
} else {
arrA[n - 1] = 0;
nBits(n - 1);
arrA[n - 1] = 1;
nBits(n - 1);
}
}
public static void main(String[] args) throws java.lang.Exception {
int n = 3;
NbitsStrings i = new NbitsStrings(n);
i.nBits(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment