Skip to content
Advertisement

Why is function not returning array in Java?

I’m making a small script to calculate the Fibonacci sequence by having an array to give how many digits i want, I just can’t figure out why my fib function is saying that there is no array being returned.

Code:

JavaScript

Advertisement

Answer

JavaScript

It’s a matter of scopes. Your only return statements is within the for loop, but if your for loop never executes, there is no return statement.

So:

JavaScript

or

JavaScript

would work, because they have return statements for all scenario’s. You’ll need to figure out which one meets your requirements. But, since you don’t actually call fib anywhere, you might also delete the method.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement