9、斐波那契数列

来源:互联网 发布:mac桌面壁纸不能平铺 编辑:程序博客网 时间:2024/06/09 08:03
public class Solution{public long Fibonacci(int n){if(n==0) return 0;if(n==1) return 1;long ret=0;long first=0,second=1;for(int i=2;i<=n;i++){ret=first+second;first=second;second=ret;}return ret;}public static void main(String args[]){int n=9;Solution sl=new Solution();System.out.println(sl.Fibonacci(n));}}

0 0