// Factorial1.java
// A program that works out the factorial of 50, that is, 50 * 49 * 48.... * 2 * 1.
// This version implements an operation called `factorial' that can get the factorial
// of any specified number
// Kevin Boone, June 1999
import java.applet.Applet;
import java.awt.*;
public class Factorial2 extends Applet
{
public void paint (Graphics g)
{
g.drawString ("Factorial of 50 is...", 20, 20);
double result = factorial(50);
g.drawString (Double.toString(result), 20, 40);
}
// Here we define the `factorial' operation
public double factorial (int factorialRequired)
{
double result = 1;
for (int i = factorialRequired; i > 1; i++)
{
result = result * i;
}
return result;
}
}
©1994-2003 Kevin Boone, all rights reserved