FileDocCategorySizeDatePackage
Factorial.javaAPI DocExample1076Sat Jan 24 10:44:24 GMT 2004je3.basics

Factorial

public class Factorial extends Object
This class doesn't define a main() method, so it isn't a program by itself. It does define a useful method that we can use in other programs, though.

Fields Summary
Constructors Summary
Methods Summary
public static intfactorial(int x)
Compute and return x!, the factorial of x

	if (x < 0) throw new IllegalArgumentException("x must be >= 0");
        int fact = 1;
        for(int i = 2; i <= x; i++)    // loop
            fact *= i;                 // shorthand for: fact = fact * i;
        return fact;