public class Factorial {
public static void main(String args[]) {
int x = Integer.parseInt(args[0]);
int result= fact(x);
System.out.println("The factorial of " + x + ": " + result);
}
static int fact(int b) {
if(b <= 1) {
return 1;
} else {
return b * fact(b-1);
}
}
}
Output:
$ java Factorial 5 The factorial of 5: 120 $ java Factorial 10 The factorial of 10: 3628800