Recursion in Methods

A recursive method is a method that calls itself to solve a smaller instance of the same problem. Recursion is often used for problems that can be divided into sub-problems, such as factorial calculation or traversing trees.

Example of Recursion (Factorial Calculation):

Code Example
Output
Factorial of 5: 120