I'm trying to figure out this compile error:
Error:(51, 4) identifier expected but '}' found.
} else if (n < 0) {
^
For this code:
def nthPowerOfX(n: Int, x:Double) : Double = {
if (n == 0) {
1.0
} else if (n < 0) {
1.0 / nthPowerOfX(n,x)
} else if (n % 2 == 0 && n > 0) {
nthPowerOfX(2, nthPowerOfX(n/2,x))
} else {
x*nthPowerOfX(n-1, x)
}
}
I tried return statements too but that didn't help nor should it matter to my understanding.
if else- Jozef DĂșc