Factorialpublic 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. |
Methods Summary |
---|
public static int | factorial(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;
|
|