/* */ Click to Join Live Class with Shankar sir Call 9798158723

Recursion in Java ?


A recursion is a method of solving the problem where the solution to a problem depends on solution to seller instances of the same problem. A recursive function is a function that calls itself during execution. This enables the function to repeat itself several times to solve a given problem.


Q.) Example of Recursion in Java ?
    public class StopRecursion {

static void methodRecurse(int n) {
  // if the precondition satisfies then stop recursion
  if (n < 0) {
    return;
  }
  // making recursive call to itself
  System.out.println(n);
  methodRecurse(n - 1);
}

public static void main(String args[]) {
    StopRecursion.methodRecurse(5);
}
}
Output
5
4
3
2
1
0