fork download
  1. /**
  2.  * Print numbers with increasing digits
  3.  * @author Prateek
  4.  *
  5.  */
  6. class IncreasingNumber {
  7.  
  8. private static int count=0;
  9. public static void main(String[] args) {
  10.  
  11. IncreasingNumber obj=new IncreasingNumber();
  12.  
  13. System.out.println("The numbers are :");
  14. obj.arrangeNum(3,5); // inclusive
  15. System.out.println("Total Numbers are : ");
  16. System.out.println(count);
  17.  
  18. }
  19.  
  20. //print increasing numbers within range of digits
  21. private void arrangeNum(int startRange , int endRange){
  22.  
  23. if(startRange == endRange +1 )
  24. return ;
  25.  
  26. arrangeNumUtil(startRange , 0);
  27.  
  28. arrangeNum(startRange + 1 , endRange) ;
  29. }
  30.  
  31. // Prints numbers with a given Number of digits
  32. private void arrangeNumUtil(int numDigits , int currentNum ){
  33.  
  34. int digit = (currentNum % 10) + 1; //next digit from current Number
  35. currentNum *= 10; // move number to left
  36. for (; digit <= 9; digit++)
  37. {
  38. if (numDigits == 1){
  39. count++;
  40. System.out.println(currentNum + digit);
  41. return;
  42. }
  43.  
  44. arrangeNumUtil(numDigits - 1, currentNum + digit);
  45. }
  46. }
  47.  
  48. }
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
The numbers are :
123
134
145
156
167
178
189
234
245
256
267
278
289
345
356
367
378
389
456
467
478
489
567
578
589
678
689
789
1234
1245
1256
1267
1278
1289
1345
1356
1367
1378
1389
1456
1467
1478
1489
1567
1578
1589
1678
1689
1789
2345
2356
2367
2378
2389
2456
2467
2478
2489
2567
2578
2589
2678
2689
2789
3456
3467
3478
3489
3567
3578
3589
3678
3689
3789
4567
4578
4589
4678
4689
4789
5678
5689
5789
6789
12345
12356
12367
12378
12389
12456
12467
12478
12489
12567
12578
12589
12678
12689
12789
13456
13467
13478
13489
13567
13578
13589
13678
13689
13789
14567
14578
14589
14678
14689
14789
15678
15689
15789
16789
23456
23467
23478
23489
23567
23578
23589
23678
23689
23789
24567
24578
24589
24678
24689
24789
25678
25689
25789
26789
34567
34578
34589
34678
34689
34789
35678
35689
35789
36789
45678
45689
45789
46789
56789
Total Numbers are : 
154