I have the following code that prints the total possible combinations of a given length of a string of numbers.
However, if I wanted to remove all the numbers with leading zeroes (i.e. 001, 002, 003) from this count, what could I do? I thought about using indexOf(), but I can't figure out how to implement it when I don't have specific set values. Any thoughts? Thank you!
public class Combinations {
public static void main(String[] args) {
printAllPossibilities("012345", 3);
System.out.println("Combinations: " + counter);
}
static void printAllPossibilities(String charSet, int length) {
printAllPossibilities_(charSet, length, "");
}
// declare counter
static int counter = 0;
static void printAllPossibilities_(String charSet, int length, String temp) {
if (length == 0) {
System.out.println(temp);
// increment counter
counter += 1;
return;
}
for (int i = 0; i < charSet.length(); i++)
printAllPossibilities_(charSet, length - 1, temp + charSet.charAt(i));
}
}