In this article we are going to print factorial of a number using recursive function. Recursive function is function called by itself during its execution . See the below example.

import java.util.Scanner;
public class FactorialRecursive {
 int fact(int n)
       int result;
       if(n==0 || n==1)
       return 1;
       result = fact(n-1) * n;
       return result;
 public static void main(String[] args) {
       System.out.println("Please Enter Number: ");
       Scanner read = new Scanner(;
       int a = read.nextInt();
       int factorial =  new  FactorialRecursive().fact(a);
       System.out.println("The factorial of given number is " + factorial);