Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Pin code generator with recursion

1. ## Pin code generator with recursion

Create program which generates pin codes (allowed numbers 1-9), the user inputs length of the code and the biggest number
This has to be done with recursion

So the program would be:

Length: 3
biggest number: 2

111
112
121
122
211
212
221
222

Length: 5
biggest number: 4

11111
11112
11113
11114
11121
...
44444

2. ## Re: Pin code generator with recursion

What have you tried?

Be sure to wrap your posted code with code tags:

[code]
[/code]

to get highlighting and preserve formatting.

3. ## Re: Pin code generator with recursion

Hello Norm,

my first approach was to create an array[length] and fill it with 1, then call a method which adds recursively every index up until the highest number, that would've been too easy...
then I got maybe the craziest idea ever, to look for the patterns and try to create a mathematical approach to it... way too complicated...
then I tried to create a method which calculates combinations, store them in an array and then sort the array. But that didn't work either.

4. ## Re: Pin code generator with recursion

The desired output looks like a series of incremented numbers in a different base and first digit. Instead of base 10 and with starting digit of 0 the base is the "biggest number" + 1 and the starting digit is 1.
So starting with 111 base 2+1 you get the first series you posted by adding 1 to the number until the max of 222 is reached.

5. ## The Following User Says Thank You to Norm For This Useful Post:

Mironoff (August 19th, 2019)

6. ## Re: Pin code generator with recursion

Thanks a million Norm! I was blind I try that right away.