Q:

Explain this recursive algorithm to print all the ordered numbers of a number of digits

I have this code to print all "ordered" numbers of a number of digits, given the number of digits
(If number is xyz, then it is ordered iff x<y<z),
The code works, but I am unable to understand the logic used in the for loop. It is recursion, but if anyone can explain more, that would be great.
class OrderedNumbers{

    public static void main(String args[]){
        printOrdered(0,0,3); // 3 digit numbers
    }

    private static void printOrdered(int number, int prev, int n) {

        if(n==0){
            System.out.println(number);
            return;
        }

        for(int i=(prev+1); i<(11-n); i++){
            printOrdered(number*10 + i, i, n-1) ;
        }

    }

}

A:

Look at the arguments.

number is the number composed so far. We multiply that by ten before we add the last digit, in order to append one more digit to that number.
prev is the value of the previous digit. The for loop will start one after that, thus ensuring that the digits within the number are ordered.
n is the number of digits yet to append. When that reaches zero, the maximal recursion depth has been reached and the number gets printed. We also use n in the computation of the upper limit in the for loop. The last digit may be no larger than 9, the second to last no larger than 8, and so on. YOu can see this from the fact that for n=1 the condition reads i<10, i.e. i<=9.

The recursive call will pass the previous number with one more digit appended, the value of that digit to ensure that the following one is larger, and the number of remaining digits reduced by one.

