WHAT IS RECURSIONS IN JAVA

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java 
 483  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    What is recursions in java

    The function called itself is called recursion. For example, a factorial program
    int factorial(int number) {
     if(number == 0) {
     return 1;
     }
     factorial_i(number, 1);
    }
    int factorial_i(int currentNumber, int sum) {
     if(currentNumber == 1) {
     return sum;
     } else {
     return factorial_i(currentNumber - 1, sum*currentNumber);
     }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!