我正在努力改变我的斐波那契音序器,以便达到第 100 项后的数字不会环绕并变成负数。如何在我编写的这段代码中使用 BigInteger:
package me.kevinossia.mystuff;
import java.util.Scanner;
public class FibonacciDisplayer
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int total;
System.out.print("This is a Fibonacci sequence displayer.\nHow many numbers would you like it to display?");
total = input.nextInt();
long[] series = new long[total];
series[0]=0;
series[1]=1;
for(int i=2;i<total;i++)
{
series[i]=series[i-1] + series[i-2];
}
for(int j=0; j<total; j++)
{
System.out.print(series[j] + "\n");
}
input.close();
}
}
我搜索了谷歌的高低,我找不到任何特定于我的案例的东西。