There are several options to solve this.
Use a bit shift operator. Start with one (000001, do the thing you need to do. Then bit shift it left (<<) one position and you get 000010. etc.
Use a power series. Math.pow(2,x) will give you the series you are looking for.
You can then use the bit values to generate the permutations in the String.
EDIT: recursive method:
public final class Permutator {
public static void main(String[] args) {
new Permutator(3, 6);
}
public Permutator(int numberOfOnes, int length) {
StringBuilder start = new StringBuilder();
for (int x = 0; x < length; x++)
start.append('0');
permutate(numberOfOnes, 0, 0, length, start);
System.exit(0);
}
public void permutate(int numberOfOnes, int first, int depth, int length, StringBuilder base) {
for (int x = first; x < length; x++) {
StringBuilder onesAndZeros = new StringBuilder(base.toString());
onesAndZeros.setCharAt(x, '1');
if (numberOfOnes == depth + 1)
System.out.println(onesAndZeros.toString());
else
permutate(numberOfOnes, x + 1, depth + 1, length, onesAndZeros);
}
}
}
Outcome for new Permutator(1, 6):
100000
010000
001000
000100
000010
000001
for new Permutator(2, 6):
110000
101000
100100
100010
100001
011000
010100
010010
010001
001100
001010
001001
000110
000101
000011
for new Permutator(4, 6):
111100
111010
111001
110110
110101
110011
101110
101101
101011
100111
011110
011101
011011
010111
001111