dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Feb 17, 2020

How to Compute the Fibonacci Number Recursively

The following code shows you how to compute the n Fibonacci number recursively:

int fibonacci(int k) {
    if (k          return k;
    }

    return fibonacci(k - 2) + fibonacci(k - 1);
}
Octavia Anghel
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date