Here you can find the source of factorial(int n)
Parameter | Description |
---|---|
n | an int |
public static int factorial(int n)
//package com.java2s; public class Main { /** Returns n!/* www. jav a 2 s .c o m*/ * @param n an int * @return n! */ public static int factorial(int n) { int returnValue; if (n < 0) { throw new IllegalArgumentException("Illegal value: " + n); } else if ((n == 0) || (n == 1)) { returnValue = 1; } else { returnValue = n * factorial(n - 1); } return returnValue; } /** Returns n! * @param n a long * @return n! */ public static double factorial(double n) { double returnValue; if (n < 0.0) { throw new IllegalArgumentException("Illegal value: " + n); } else if ((n == 0) || (n == 1)) { returnValue = 1.0; } else { returnValue = n * factorial(n - 1.0); } return returnValue; } }