Skip to content

Instantly share code, notes, and snippets.

@tyano
Created August 26, 2010 16:07
Show Gist options
  • Save tyano/551686 to your computer and use it in GitHub Desktop.
Save tyano/551686 to your computer and use it in GitHub Desktop.
public class Factorial {
static int fact(int n) { return n == 0 ? 1 : n * fact(n - 1); }
public static void main(String[] args) {
int n = args.length == 0 ? 1 : Integer.parseInt(args[0]);
for(int i = 1; i <= n; i++) System.out.println(i + "! = " + fact(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment