Title Description
We all know that Fibonacci number, and now asked to enter an integer n, you output the n-th Fibonacci number Fibonacci sequence of item (from 0, the first 0 is 0).
n<=39
Topic links:
package com.sunshine.OFFER66_SECOND; import org.junit.Test; public class A7_Fibonacci { @Test public void test() { System.out.println(Fibonacci(0)); } public int Fibonacci(int n) { if(0 == n){ return 0; } int a = 0; int b = 1; int ans = 1; n--; while (n > 0) { Years = a + b; a = b; b = years; n - ; } Return year; } }