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 create an html page with frames and frameset

1. Write a program to insert a new element at end as well as at a given position in an array in Java

1. To familiarize with network devices like switch, hub, routers and bridges in LaTex