I\'ve been looking around quite a bit to solve my issue. I got many problems solved but this one is still haunting me :S It\'s been a long time I haven\'t touch Java program
You can try Recursion to solve this issue:
public static void printPermutations(int[] n, int[] Nr, int idx) {
if (idx == n.length) { //stop condition for the recursion [base clause]
System.out.println(Arrays.toString(n));
return;
}
for (int i = 0; i <= Nr[idx]; i++) {
n[idx] = i;
printPermutations(n, Nr, idx+1); //recursive invokation, for next elements
}
}
More info can be had from this link: Combinatorics: generate all “states” - array combinations
You can replicate the same logic here as well.