This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
So the initial number defines the allowed order among digits? And you're supposed to form all subnumbers which preserve the allowed order among digits? That's simpler than it looks really.
Say the initial number is 123. The first step is to split the initial number into individual digits and store them in an int array. To just print the digits will generate all subnumbers of length 1,
But how to generate all valid subnumbers of length 2? That can be done by introducing a second nested loop.
As you can see the nested loop starts from the index of the outer loop plus 1. This means it will only consider digits that safely can be added to the current number of the outer loop.
Now you can easily generate all valid 3 digit numbers by introducing yet another nested loop following the same pattern. (There should be one such number only by the way, namely the initial number).
That's all fine but what about if you don't know how many digits there are in the initial number? How can you have a variable number of nested loops? The answer is recursion. The above can be reformulated as a recursive method where each recursive call represents one step deeper down the loop nesting.