I want to find the 2^n permutations of any size based on user input. I have no idea how to do this. I know that I have to use recursion. Unlike most examples I've seen, the parameter of the function is only the number input, there is no string that can be used to make all the permutations. All the permutations are to be stored in an arrayList and output to the user. i.e (input 3) output: 000 001 010 011 100 101 110 111 Here's the code I have so far:
public static void printBin(int bits) {
ArrayList<String> binaryArray = new ArrayList<String>();
if(bits == 0) {
System.out.println(binaryArray);
}
else {
for (String string2 : binaryArray) {
String comp = "";
if (comp.length() <= string2.length()) {
comp = string2;
string = comp;
}
string.concat("0");
binaryArray.add(string);
printBin(bits - 1);
string.concat("1");
binaryArray.add(string);
printBin(bits-1);
}
}
}
Thanks in advance.