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

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN