Skip to content

Instantly share code, notes, and snippets.

@tyano
Created August 26, 2010 15:56
Show Gist options
  • Save tyano/551669 to your computer and use it in GitHub Desktop.
Save tyano/551669 to your computer and use it in GitHub Desktop.
object Factorial {
def fact(n: Int): Int = if(n == 0) 1 else n * fact(n - 1)
def main(args: Array[String]) = {
val n = if(args.length == 0) 1 else Integer.parseInt(args(0))
1 to n foreach {i => println(i + "! = " + fact(i))}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment