Java Utililty Methods Factorial

List of utility methods to do Factorial

Description

The list of methods to do Factorial are organized into topic(s).

Method

doublefactorial(double n)
This will return the factorial of the given number n.
if (n == 1 || n == 0)
    return 1;
for (double i = n; i > 0; i--, n *= (i > 0 ? i : 1)) {
return n;
doublefactorial(double n)
factorial
if (n < 0.0)
    throw new Error("Can not compute the factorial of a negative number");
if (n <= 1.0)
    return 1.0;
if (n <= 4.0) {
    int floor = (int) Math.floor(n);
    int ceil = (int) Math.ceil(n);
    if (floor == ceil)
...
intfactorial(final int a)
factorial
int factorialVal = 1;
for (int i = 2; i <= a; i++) {
    factorialVal = factorialVal * i;
return factorialVal;
longfactorial(final long value)
Takes the factorial of a value.
long fac = 1;
for (int i = 0; i < value; i++) {
    fac *= (value - i);
return fac;
doublefactorial(int c)
factorial
if (c < 0)
    throw new IllegalArgumentException("Can't take the factorial of a negative number: " + c);
if (c == 0)
    return 1;
return c * factorial(c - 1);
intfactorial(int i)
factorial
return f[i];
intfactorial(int input)
factorial
int output;
switch (input) {
case 0: {
    output = 1;
    break;
case 1: {
    output = 1;
...
longfactorial(int integer)
Compute the factorial of an integer
if (integer < 1) {
    return 0;
if (integer < 3) {
    return integer;
long factorial = integer;
integer--;
...
longfactorial(int n)
Computes n!.
if (n == 0)
    return 1;
long fact = n;
for (int i = n - 1; i > 1; --i)
    fact *= i;
return fact;
intfactorial(int n)
Standard factorial calculation.
if (n == 0)
    return 1;
int fact = 1;
for (int i = 1; i <= n; i++)
    fact *= i;
return fact;