How to calculate factorial in Scala

1 Answer

0 votes
object MyClass {
    def factorial(n: Int): BigInt = 
        if (n == 0) 1 
            else factorial(n - 1) * n

    def main(args: Array[String]): Unit = {
        print(factorial(5));
    }
}



/*
run:

120

*/

 



answered Dec 20, 2022 by avibootz
...