What will be the result of following code execution?
object Main extends App {
  def gcd(a: Int, b: Int) =
    if (b == 0) a else gcd(b, a % b)

  println(gcd(5, 15))
}
Explanation
Return type is required for recursive functions in Scala. That is why code will not compile.
More information: When is a return type required for methods in Scala?

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback