What is recursion in Java also explain it, and write code for reverse string using recursion technique?
What is recursion in Java also explain it, and write code for reverse string using recursion technique?
Software Developer
Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur. SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer
Recursion is the process in which a function calls itself directly or indirectly and the corresponding functions are called recursive functions.
Recursive function or method calls store new parameters and local variables on the stack, which are then removed as we return from the recursive calls. While recursive functions enable us to develop simple and clear solutions for certain problems easily, they can also lead to slow execution due to added overhead and additional function calls.
The concept of recursive function can be used to find the factorial of a number as shown below:
Here, if factorial() is called with an argument of 1, then it returns 1 else it returns the product of n*factorial(n-1).
Code for reversing string using recursion in java
I have no idea about the theory parts.
I try to write code for a reverse string in recursion.
Output →
5-saj1-wu-sakfhjdsa-afsdfhjk
I hope you enjoy this answer. Bye !!!
Recusion is a method where a function calls directly itself. In java, recursion is recognised as a process where any particular function calls itself. This process is used for avoiding difficult problems by making them comparatively easier. This method is used rarely and when any complicated type of code is needed to write then this process is used to make that simple. It is the process where the items are repeated in a same kind of manner.
The code for reverse string using recursion will be as follows: