Home > DeveloperSection > Interviews > What is recursions in java

Posted on    July-14-2015 11:30 PM

 Java Java 
Ratings:
 1 Answer(s)
  304  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    July-14-2015 11:30 PM

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);
 }
}

Don't want to miss updates? Please click the below button!

Follow MindStick