Hi!
I would like to print all combinations of
n integers.
For instance, the below code prints all combinations of integers 000-999:
public class Test {
public Test(){
for(int a = 0; a < 10; a++){
for(int b = 0; b < 10; b++){
for(int c = 0; c < 10; c++){
System.out.println((a+""+b+""+c));
}
}
}
}
public static void main(String[] args){
new Test();
}
}
If I want all combinations between 00000-99999 I can add two more for-loops. But is it possible to make the code nicer by, for example, create a recursive method or something simillar? I tried but failed since the recursive loop always ended up in itself and throwed a java.lang.StackOverflowError.