Thursday, June 9, 2016

Factorial Program in Java using recursion

Hi Folks , Today I am going to talk about the factorial program of 'n' numbers in java , how to implement it and what is the time complexity all other things , in my earlier post I have talked about Tower of Hanoi problem 
You can also see other Sorting program
Bubble Sort 
Selection Sort
Insertion Sort 


IMPLEMENTATION OF FACTORIAL 


public class FactorialRecursion {
// main method
public static void main(String[] args) {

System.out.println(factorial(5)); // need to find the factorial of 5
}

public static  int factorial(int i)
{
if(i==0) return 1;
else 
return i*factorial(i-1);
}


}


OUTPUT -   120

Time Complexity - The Time Complexity of Factorial Function is O(n).

Guys if you have any problem regarding the code  and any suggestion , please let me know. I will try to help / Improve.

Thank for reading

- Noeik