Title: Everyone knows the Fibonacci sequence, and now requires an integer n, please output the nth item of the Fibonacci sequence (starting from 0, the 0th item is 0).
- code show as below
1 public class Demo7 { 2 3 public static void main(String[] args) { 4 int fibonacci = Fibonacci(40); 5 System.out.println(fibonacci); 6 } 7 8 public static int Fibonacci(int n) { 9 if (n == 0) 10 return 0; 11 if (n == 1 || n == 2) 12 return 1; 13 14 returnFibonacci (n - 1) + Fibonacci (n - 2 ); 15 } 16 }