A recursion is the attribute that allows the method to call itself. A method that calls itself is said to be recursive method.
The classic example of recursion is the computation of factorial of a number.
- Factorial of 3 is 3*2*1 = 6
- Factorial of 6 is 6*5*4*3*2*1 = 720
Method calling itself for returning the factorial of a number:
int fact(int n)
result = fact(n-1)*n;
Lets implement this factorial program on Eclipse IDE:
2. Create fact( ) method such that it receives integer value and returns the factorial of the received integer as show below and save:
4. Create an object ‘object1’ to access fact( ) method in Factorial class as shown below:
View original post 78 more words