Java Implementation Fibonacci sequence

Source: Internet
Author: User
Package Algorithm.cxg.Fibonacci;

Import Java.util.Scanner;  /** * Implementation of the Fibonacci pull function * Fibonacci sequence: * Starting with 0 and 1, the Faiponasi coefficients are added to the previous two numbers, and the form is as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, .... * In mathematics, it is defined in a recursive way: * f_0=0 * f_1=1 * f_n = f_{n-1}+ f_{n-2} * Implementation requirements: input of the
		Ordinal n returns to get corresponds to Fibonacci that West number * @author Admin * */public class Fibonacci {public static void main (string[] args) {/*//The first two items of the definition series
		int a=0,b=1;
        Defines the nth item Scanner scan = new Scanner (system.in);
        System.out.println ("Please enter the number of n items within 30 items of the Fibonacci series:");
		int n = scan.nextint ();
		Output System.out.println (the number of nth items within 30 of the Fibonacci series is: ");
		System.out.print (+ "\ n" +b+ "\ n");
			Based on the function of the series, the calculation for (int i = 0; I <= i++) {n=a+b;
			A=b;
			B=n;
		System.out.println (n+ "T");
		}*/System.out.println (the number of nth items within 30 of the Fibonacci series is: ");
		for (int j = 1; J <= J + +) {System.out.print (Getfibonacco (j) + "T");
		}///recursive function implementation sequence public static int Getfibonacco (int i) {if (i==1) {0;else if (i==1 | | i==2) {return 1;
		else {return Getfibonacco (i-1) +getfibonacco (i-2); }
	}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.