集册 Java实例教程 创建斐波那契级数

创建斐波那契级数

欢马劈雪     最近更新时间:2020-01-02 10:19:05

516
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建斐波那契级数

 

public class Main {

 
 /* from 
 nowjava*/

        public static void main(String[] args) {

               

                //number of elements to generate in a series

                int limit = 20;

               

                long[] series = new long[limit];

               

                //create first 2 series elements

                series[0] = 0;

                series[1] = 1;

               
               /** from 
               时 代      J a v a   公   众 号 - nowjava.com**/

                //create the Fibonacci series and store it in an array

                for(int i=2; i < limit; i++){

                        series[i] = series[i-1] + series[i-2];

                }

               

                //print the Fibonacci series numbers

               

                System.out.println("Fibonacci Series upto " + lim
展开阅读全文