Determining whether a number is a Fibonacci number

前端 未结 14 1219
暗喜
暗喜 2021-01-18 05:35

I need to to write a Java code that checks whether the user inputed number is in the Fibonacci sequence.

I have no issue writing the Fibonacci sequence to output, b

14条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 06:42

    Instead of passing the index, n, write a function that takes a limit, and get it to generate the Fibonacci numbers up to and including this limit. Get it to return a Boolean depending on whether it hits or skips over the limit, and you can use this to check whether that value is in the sequence.

    Since it's homework, a nudge like this is probably all we should be giving you...

提交回复
热议问题