Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop p

java program to get factorial of a number

factorial in java

Java Program to find factorial of a number

The calculation of factorial is pretty much an example of recursion technique in programming. 

But there is a drawback that the recursion isn't memory efficient if you don't care about it, it isn't the problem for you. 

It's a choice to save the time of a programmer.

The factorial of any number that is n > 1  multiplied by the factorial of n - 1. See the implementation.

for example

factorial(4)

4 * factorial(3)

4 * 3 * factorial(2)

4 * 3 * 2 * factorial(1)

The factorial of a positive integer x is equal to the product of all positive integers from 1 to x inclusively. 

Also by definition, the factorial of 0 is 1.

download or see the complete code for calculating the factorial of a number in java

No comments:

Post a Comment