//////// File Factorial.java /////// // run with kaffe Factorial 5 import java.lang.Integer; // for parseInt public class Factorial { public static int factorial(int n) { int ans = 1; while (n > 1) { ans = ans * n; n = n - 1; } return(ans); } public static void main(String args[]) { int j; if (args.length != 1) { System.err.println("Factorial takes one integer argument"); System.exit(1); // abnormal termination of main } j = Integer.parseInt(args[0]); // string to int conversion if ( j < 0 ) { System.err.println("Arg to Factorial must not be negative"); System.exit(1); // abnormal termination of main } System.out.print("factorial(" + args[0] + ")= "); System.out.println(factorial(j)); } }