/**
* This program computes the factorial of a number
*/
public class Factorial { // Define a class
public static void main(String[] args) { // The program starts here
int input = Integer.parseInt(args[0]); // Get the user's input
double result = factorial(input); // Compute the factorial
System.out.println(result); // Print out the result
} // The main() method ends here
public static double factorial(int x) { // This method computes x!
if (x < 0) // Check for bad input
return 0.0; // if bad, return 0
double fact = 1.0; // Begin with an inital value
while(x > 1) { // Loop until x equals 1
fact = fact * x; // Multiply by x each time
x = x - 1; // and then decrement x
} // Jump back to start of loop
return fact; // Return the result
} // factorial() ends here
} // The class ends here
"If this command prints ant error messages, you probably got something wring when you typed in the program. If it does not print any error messages, however, the compilation has succseded, and javac creates a file called Factorial.class." (Flanagan 99, s10)
