|
|
`Factorial1' example program: demonstrates loop operations
Factorial1.java
// Factorial1.java
// A program that works out the factorial of 50, that is, 50 * 49 * 48.... * 2 * 1.
// Kevin Boone, June 1999
import java.applet.Applet;
import java.awt.*;
public class Factorial1 extends Applet
{
public void paint (Graphics g)
{
double result = 1;
int factorialRequired = 50;
for (int i = factorialRequired; i > 1; i--)
{
result = result * i;
}
g.drawString ("Factorial of 50 is...", 20, 20);
g.drawString (Double.toString(result), 20, 40);
}
}
|