Java Factorial factorial(double n)

Here you can find the source of factorial(double n)

Description

This will return the factorial of the given number n.

License

Apache License

Parameter

Parameter Description
n the number to getFromOrigin the factorial for

Return

the factorial for this number

Declaration

public static double factorial(double n) 

Method Source Code

//package com.java2s;
/*//from  w  ww .jav  a 2s.c  o m
 *
 *  * Copyright 2015 Skymind,Inc.
 *  *
 *  *    Licensed under the Apache License, Version 2.0 (the "License");
 *  *    you may not use this file except in compliance with the License.
 *  *    You may obtain a copy of the License at
 *  *
 *  *        http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *    Unless required by applicable law or agreed to in writing, software
 *  *    distributed under the License is distributed on an "AS IS" BASIS,
 *  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *    See the License for the specific language governing permissions and
 *  *    limitations under the License.
 *
 */

public class Main {
    /**
     * This will return the factorial of the given number n.
     * @param n the number to getFromOrigin the factorial for
     * @return the factorial for this number
     */
    public static double factorial(double n) {
        if (n == 1 || n == 0)
            return 1;
        for (double i = n; i > 0; i--, n *= (i > 0 ? i : 1)) {
        }
        return n;
    }
}

Related

  1. factorial(double n)
  2. factorial(final int a)
  3. factorial(final long value)
  4. factorial(int c)