X486: Recursion - Perrin Numbers

In mathematics, the Perrin Numbers are defined by the recursion relation

P(n) = P(n - 2) + P(n -3) for n > 2

with initial values

  • P(0) = 3
  • P(1) = 0
  • P(2) = 2

Define a recursive function that gives the nth term in the Perrin sequence.

Examples:

perrinNumber(0) -> 3
perrinNumber(1) -> 0
perrinNumber(2) -> 2
perrinNumber(3) -> 3

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.