List of utility methods to do Factorial
int | factorial(int n) int wrapper for #factorial(float) return (int) factorial((float) n); |
long | factorial(int n) Utility method for computing the factorial n! if (n < 0 || n > 20) { throw new IllegalArgumentException( "The factorial can only " + "be calculated for numbers n with 0 <= n <= 20 (currently n = " + n + "). Please try to consider less modifications."); if (n == 0 || n == 1) { return 1; long f = 1; for (int i = 2; i <= n; i++) { f *= i; return f; |
long | factorial(int n) n! long r = 1; while (n > 0) r *= n--; return r; |
double | factorial(int n) factorial if (n < 0) { throw new IllegalArgumentException("factorial can only handle n >= 0"); if (n > m_lastFactorial_id) { double result = factorials[m_lastFactorial_id]; for (int i = factorials.length; i <= n; i++) { result = result * i; return result; } else { return factorials[n]; |
long | factorial(int n) factorial return (n < 2) ? n : (n * factorial(n - 1));
|
long | factorial(int n) factorial if (n < 0) throw new IllegalArgumentException(); if (n < 2) return 1; long result = 1; for (int i = n; i >= 2; i--) result *= i; return result; ... |
int | factorial(int n) Find the factorial of the input number if (n < 0) { throw new IllegalArgumentException("Input should be nonnegative."); } else if (n < 2) { return 1; } else { int accum = 1; for (int i = n; i > 0; i--) accum *= i; ... |
int | factorial(int n) factorial int f = 1; for (int i = 1; i <= n; i++) { f *= i; return f; |
long | factorial(int n) factorial long n_factorial = 1; if (n == 1) return n_factorial; if (n < 0) throw new IllegalArgumentException("Cannot calculate factorial of negative numbers!"); if (n > 20) throw new IllegalArgumentException("I can calculate up to 20!."); for (int i = 2; i <= n; i++) { ... |
double | factorial(int n) basically a lookup-function for n! if (n < 0) { throw new IllegalArgumentException("factorial can only handle n >= 0"); if (n > LAST_DOUBLE_FACTORIAL) { throw new ArithmeticException( "Can't calculate a factorial for n larger then " + factorials.length + " within doubles."); } else { return factorials[n]; ... |