Posted by : Unknown Sunday 5 July 2015


class Factorial 
{
     int fact(int n) 
     {
          int result;
          if(n==1) return 1;
          result = fact(n-1) * n;
          return result;
     }
}

class Recursion 
{
     public static void main(String args[]) 
     {
          Factorial f = new Factorial();
          System.out.println("Factorial of 4 is " + f.fact(4));
     }
}

Output:

Factorial of 4 is 24

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Translate

Popular Post

Total Pageviews

- Copyright © Learning Java Program - Powered by Blogger -