Javalobby - Comments for "Finding Factorial of a Number in Java"
http://java.dzone.com/articles/finding-factorial-number-java
Comments for "Finding Factorial of a Number in Java"enOne line in Scala:def
http://java.dzone.com/articles/finding-factorial-number-java#comment-93637
<!--paging_filter-->One line in Scala:<br /><br /><pre>def factorial(n: Int) = BigInt(1) to n product</pre><br />Test:<br /><pre class="groovy">scala> (21 to 30) foreach (n => printf("The factorial of %d is %d\n", n,factorial(n)))
The factorial of 21 is 51090942171709440000
The factorial of 22 is 1124000727777607680000
The factorial of 23 is 25852016738884976640000
The factorial of 24 is 620448401733239439360000
The factorial of 25 is 15511210043330985984000000
The factorial of 26 is 403291461126605635584000000
The factorial of 27 is 10888869450418352160768000000
The factorial of 28 is 304888344611713860501504000000
The factorial of 29 is 8841761993739701954543616000000
The factorial of 30 is 265252859812191058636308480000000
scala> (0 to 3) foreach (n => printf("The factorial of %d is %d\n", n,factorial(n)))
The factorial of 0 is 1
The factorial of 1 is 1
The factorial of 2 is 2
The factorial of 3 is 6
</pre><br /><br />Fri, 01 Feb 2013 09:38:53 -0500flushtimecomment 93637 at http://java.dzone.com