Java Factorial factorial(long num)

Here you can find the source of factorial(long num)

Description

Gets the factorial of a number

License

Open Source License

Parameter

Parameter Description
num Number to start at

Return

The factorial

Declaration

public static long factorial(long num) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//w  ww .  j a  v a  2  s.  c om
     * Gets the factorial of a number
     *
     * @param num Number to start at
     * @return The factorial
     */
    public static long factorial(long num) {
        if (num == 0)
            return 1;

        if (num == 2 || num == 1) {
            return num;
        } else {
            return num * factorial(num - 1);
        }
    }
}

Related

  1. factorial(int x)
  2. Factorial(int x)
  3. factorial(int x)
  4. factorial(long l)
  5. factorial(long n)
  6. factorialAsDouble(int n)
  7. factorialAsDoubleIncludeDivisor(int n, double divisor)
  8. factorialCheckBounds(int n)
  9. factorialDouble(final int n)