Ad

Getting an integer n, return the next digit after the nth digit of the fibonacci sequence.

For example:

n == 3, return 2.

n == 2, return 1.

n == 12, return 144.

Fib sequence. 0,1,1,2,3,5,8,13,21,34,55,89,144. . .

public class nthFib{

    public static int fib(int n){
      return n == 1 ? 1 : n == 0 ? 0 : (fib(n - 1) + fib(n - 2));
    }
}