[Solved] “StackOverflow” error when using Recursion in Java [closed]


Here is the problem:

func(no++);

Let’s say no is 32. This will pass 32 to func and then increment it. Which means that you are once again calling the function with a value of 32. And when that function hits this line, it will, once again, pass that 32 to func. Hence, an infinite recursive loop.

You can fix this bug like this:

func(++no);

Now it will increase no before calling func. no will be 33, it will match its reverse, and all will be well.

3

solved “StackOverflow” error when using Recursion in Java [closed]