I want the algorithm to generate all possible N-digit numbers whose numbers are in ascending order.
for example: if N = 3, then the possible numbers are: 012,123,234,246,567,259, because:
0 <1 & Lt; 2
...
2 <5 & Lt; nine
and etc.
How can i do this?
I developed the following algorithm, but it only generates numbers with consecutive increasing digits, such as 123,234,345,456,567, etc. Consequently, a large set of numbers is missing.
private static void generate(int start,int n) { if((start+n)>9) return; else { for(int i=0;i<n;i++) System.out.print(start+i); System.out.println(); generate(start+1,n); } }
source share