Factorial Program using Recursion in Java.

class Main
{
   static int Fact(int num){
     if(num == 1){
       return 1;
     }
     else{
       return num*Fact(num-1);
     }
   }
   public static void main(String args[])
   {
    int z = Fact(5);
    System.out.println(z);
   }
}

we calculated factorial of number 5. You can pass any number in the place of 5.

Leave a Comment