Friday, July 13, 2018

Fibonacci Number

Problem statement:
Given a number n, print n-th Fibonacci Number.
Input : n = 2 
Output : 1 
Input : n = 9 
Output : 34
public class FibonacciSeries {
    static int fib(int n) {
        if (n <= 1)
            return n;
        return fib(n - 1) + fib(n - 2);
    }
    public static void main(String args[]) {
        int n = 9;
        System.out.println(fib(n));
    }
}
Output:
34

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...