Does anyone have Java code for generating all VARIATIONS WITH REPETITION?
There are plenty of permutation and combination examples available, and variations must be
This works as is, and it's the easiest for you to study.
public class Main {
public static void main(String args[]) {
brute("AB", 3, new StringBuffer());
}
static void brute(String input, int depth, StringBuffer output) {
if (depth == 0) {
System.out.println(output);
} else {
for (int i = 0; i < input.length(); i++) {
output.append(input.charAt(i));
brute(input, depth - 1, output);
output.deleteCharAt(output.length() - 1);
}
}
}
}