scala - simple recursive function error - java.lang.StackOverFlow error - output exceeds cut off limit -


i practicing scala's simple recursive function. book

def calculatepower(x:int, y:int): long = {       if (x>=1)          x*calculatepower(x,y-1)       else 1    }   calculatepower(2,2) 

your method stack overflows because doesn't terminate , stack frames accumulates until there no more room.

if (x>=1) x*calculatepower(x,y-1) test if x greater or equal 1 in recursive call decrement y!


Comments