How To Implement Recursion In Java
Rate this article
0 out of 5
In this tutorial we will show you how to implement recursion in java. After viewing the video tutorial, download the source code and try to modify the code so as to get a feel of what is learned in this video tutorial.


Source Code
Recur.java
import java.io.*;
class Factorial
{
int fact(int n) 
{
   int result; 
   if(n==1) 
    {
     return 1;
    }
    result=fact(n-1)*n;
    return result;
}
}
class Recur
{
public static void main(String args[])
  {
   Factorial f=new Factorial();
   System.out.println("Factorial of 3 is"+f.fact(3));
   System.out.println("Factorial of 4 is"+f.fact(4));
   System.out.println("Factorial of 5 is"+f.fact(5));
  }
}


Source Code

About The Author
TekTips Videos

Number Of articles Posted
27
Number Of Messages Posted
0
Joined Date
04/02/2013
   
Author
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments

 
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android