Program to find the factorial using recursion [Java]

public class Factorial {

    static int findFactorial(int n){      

        if (n == 1)      

          return 1;      

        else      

          return(n * findFactorial(n-1));  //calling same method    

  } 

     

public static void main(String[] args) {  

System.out.println("Factorial of 5 is: " + findFactorial(5));  

}  

}

Output:

Factorial of 5 is: 120

Comments

Popular posts from this blog

String class in C# (Methods and properties)

SQL Server Queries

Simple calculator (Console application/Java)