package fibonacci;
import java.math.BigInteger;
import java.math.*;
public class fibo {
public static void main(String[] args) {
//number of elements to generate in a series
BigInteger sum;
BigInteger[] series= new BigInteger[4000000];
//long[] series = new long[4000000];
//create first 2 series elements
series[0] = BigInteger.valueOf(1);
series[1] = BigInteger.valueOf(2);
//create the Fibonacci series and store it in an array
for(int i=2; i < series.length; i++){
series[i] = series[i-1].add(series[i-2]);
if (series[i].mod(BigInteger.valueOf(2)) == BigInteger.valueOf(0)){
sum = sum.add(series[i]); //error here
}
}
System.out.println("Fibonacci Series sum " + sum); //error here
}
}
我正在尝试计算斐波那契的偶数之和。我需要在这里改变什么?还是应该使用 .subtract 重写整个程序?