Java language Feibolaqi series

Fibonacci number Overview

Fibonacci number (Fibonacci sequence), also known as golden columns, because mathematician Leonardo Fibonacci (Leonardoda Fibonacci) as an example to the rabbit breeding and the introduction, it is also known as the " Rabbit series ," referring to such a series is: 1,1,2,3,5,8,13,21,34, ...... mathematically, Fibonacci numbers are listed in the following recursive method is defined: F. (. 1) = . 1, F. (2) =. 1,  F. (n-) = F. (n--. 1) + F. (n-- 2) ( n-  ≥. 3, n-  ∈ N *) in modern physics, quasi- crystalline structure field, chemistry, Fei fibonacci number sequence has a direct application, for which the American mathematical Society published a mathematics magazine "fibonacci Quarterly" in the name since 1963, is devoted to research in this area.

Feibolaqi example the number of columns

0、1、1、2、3、5、8、13、21、34.........

Feibolaqi columns formula

Fn = F (n-1) + F (n-2)? Where n is a positive integer and n is greater than or equal to 2

Java language Feibolaqi series

package com.algorithm;
/**
 * 本文作者:谷哥的小弟 
 * 博客地址:http://blog.csdn.net/lfdfhl
 */
public class TestFibonacci {

	public static void main(String[] args) {
		int result = fibonacci(8);
		System.out.println(result);
	}
	
	public static int fibonacci(int index) {
		if(index>=0) {
			if(index==0) {
				return 0;
			}else if(index==1) {
				return 1;
			}else {
				return fibonacci(index-1)+fibonacci(index-2);
			}
		}else {
			System.out.println("请你重新输入");
			return -1;
		}
	}

}

 

 

Released 1022 original articles · won praise 1986 · Views 2.38 million +

Guess you like

Origin blog.csdn.net/lfdfhl/article/details/6173906