Factorial of an integer

The factorial of an integer is calculated by multiplying all the numbers from 1 to the given number.

F(n) = F(1)*F(2)…F(n-1)*F(n).

We can use recursion to find the factorial of an integer.

public static long factorial(long n) { if (n == 1) return 1; else return (n * factorial(n - 1)); }

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API