Java Factorial factorial(int integer)

Here you can find the source of factorial(int integer)

Description

Compute the factorial of an integer

License

Open Source License

Parameter

Parameter Description
integer Integer to have is factorial

Return

integer!

Declaration

public static long factorial(int integer) 

Method Source Code

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

public class Main {
    /**//from   w  w w  . jav  a2  s  . co  m
     * Compute the factorial of an integer
     * 
     * @param integer
     *           Integer to have is factorial
     * @return integer!
     */
    public static long factorial(int integer) {
        if (integer < 1) {
            return 0;
        }

        if (integer < 3) {
            return integer;
        }

        long factorial = integer;

        integer--;

        while (integer > 1) {
            factorial *= integer;

            integer--;
        }

        return factorial;
    }
}

Related

  1. factorial(final int a)
  2. factorial(final long value)
  3. factorial(int c)
  4. factorial(int i)
  5. factorial(int input)
  6. factorial(int n)
  7. factorial(int n)
  8. factorial(int n)
  9. factorial(int n)