Concept of recursion using factorial in java

public class P_07_recursion_factorial

    static int factorial(int n)
    {     
          if (n == 1)     
            return 1;     
          else     
            return(n * factorial(n-1));     
    }       
public static void main(String[] args)

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

}

Output :


Comments

Popular posts from this blog

To implement the various components of HTML5 Canvas

Program to illustrate the concept of templates.

Program to illustrate the order of execution of constructors and destructors in inheritance.