[Wins the offer] Fibonacci number

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:

https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3?tpId=13&tqId=11160&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking

 

 

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; 
    } 
}

 

Guess you like

Origin www.cnblogs.com/MoonBeautiful/p/11417706.html