如果一个数字是斐波那契数列,如果每个后续数字都是前两个数字之和。
在下面的示例中,我们可以在 jshell 工具中实现斐波那契数列系列。
c:\users\user\>jshell| welcome to jshell -- version 9.0.4| for an introduction type: /help introjshell> int x=0, y=1, z=0, count=5;x ==> 0y ==> 1z ==> 0count ==> 5jshell> {...> system.out.println(x+"\n"+y);...> for(int i=0; i<count; i++) {...> x=y; y=z;...> z = x+y;...> system.out.println(z);...> }...> }0112358jshell>
以上就是如何在java 9的jshell中实现斐波那契数列?的详细内容。
