Factorial in Scala
Example for versions
Simply Scala
This examples shows how to define ! as a method applied to Int.
def factorial(n: Int): BigInt =
if (n == 0) 1
else factorial(n - 1) * n
class Factorizer(n: Int) {
def ! = factorial(n)
}
implicit def int2fact(n: Int) = new Factorizer(n);
for {i <- List.range(0, 17)}
println(i + "! = " + (i!))
Comments
]]>blog comments powered by Disqus
]]>