美文网首页
斐波那契公式java学习

斐波那契公式java学习

作者: 檬子树桥 | 来源:发表于2018-02-01 22:15 被阅读0次

public static void fanzhi(){

long[] a =new long [13];

a[0] = 1 ;

a[1]= 1;

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

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

}

for(long i :a){

System.out.println(i);

}

-------------------------------------------------

------------------------BigInteger类型-----------------------------

BigInteger[] b = new BigInteger[101];

b[0] =BigInteger.ONE;

b[1] = BigInteger.ONE;

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

b[i] = b[i-2].add(b[i-1]);

}

for(BigInteger i :b){

System.out.println(i);

}

相关文章

网友评论

      本文标题:斐波那契公式java学习

      本文链接:https://www.haomeiwen.com/subject/uybjzxtx.html