/**
* Print numbers with increasing digits
* @author Prateek
*
*/
class IncreasingNumber {
private static int count=0;
public static void main
(String[] args
) {
IncreasingNumber obj=new IncreasingNumber();
System.
out.
println("The numbers are :"); obj.arrangeNum(3,5); // inclusive
System.
out.
println("Total Numbers are : ");
}
//print increasing numbers within range of digits
private void arrangeNum(int startRange , int endRange){
if(startRange == endRange +1 )
return ;
arrangeNumUtil(startRange , 0);
arrangeNum(startRange + 1 , endRange) ;
}
// Prints numbers with a given Number of digits
private void arrangeNumUtil(int numDigits , int currentNum ){
int digit = (currentNum % 10) + 1; //next digit from current Number
currentNum *= 10; // move number to left
for (; digit <= 9; digit++)
{
if (numDigits == 1){
count++;
System.
out.
println(currentNum
+ digit
); return;
}
arrangeNumUtil(numDigits - 1, currentNum + digit);
}
}
}
LyoqCiAqIFByaW50IG51bWJlcnMgd2l0aCBpbmNyZWFzaW5nIGRpZ2l0cwogKiBAYXV0aG9yIFByYXRlZWsKICoKICovCiBjbGFzcyBJbmNyZWFzaW5nTnVtYmVyIHsKCglwcml2YXRlIHN0YXRpYyBpbnQgY291bnQ9MDsgCglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgoJCUluY3JlYXNpbmdOdW1iZXIgb2JqPW5ldyBJbmNyZWFzaW5nTnVtYmVyKCk7CgkJCgkJU3lzdGVtLm91dC5wcmludGxuKCJUaGUgbnVtYmVycyBhcmUgOiIpOwoJCW9iai5hcnJhbmdlTnVtKDMsNSk7IC8vIGluY2x1c2l2ZQoJCVN5c3RlbS5vdXQucHJpbnRsbigiVG90YWwgTnVtYmVycyBhcmUgOiAiKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oY291bnQpOwoJCQoJfQoKCS8vcHJpbnQgaW5jcmVhc2luZyBudW1iZXJzIHdpdGhpbiByYW5nZSBvZiBkaWdpdHMKCXByaXZhdGUgdm9pZCBhcnJhbmdlTnVtKGludCBzdGFydFJhbmdlICwgaW50IGVuZFJhbmdlKXsK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