fibonaccinumber.java

来自「随书的代码」· Java 代码 · 共 28 行

JAVA
28
字号
package com.macfaq.math;import java.math.BigInteger;public class FibonacciNumber {  public static BigInteger calculate(int n) {      if (n <= 0) {      throw new IllegalArgumentException(       "Fibonacci numbers are only defined for positive integers"      );    }    BigInteger low  = BigInteger.ONE;    BigInteger high = BigInteger.ONE;        for (int i = 3; i <= n; i++) {      BigInteger temp = high;      high = high.add(low);      low = temp;    }        return high;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?