透過字串在 Java 中建立 BigInteger


BigInteger 類用於超出基本資料型別限制的大整數計算。它提供模組算術、GCD 計算、質數測試、質數生成、位操作以及一些其他雜項運算。

首先,設定一個字串 −

String str = "268787878787687";

現在,建立一個新物件用於 BigInteger 並傳遞上面的字串 −

BigInteger bInteger = new BigInteger(str);

下面是一個示例 −

示例

 即時演示

import java.math.BigInteger;
public class Demo {
   public static void main(String[] argv) throws Exception {
      String str = "268787878787687";
      BigInteger bInteger = new BigInteger(str);
      System.out.println(bInteger);
   }
}

輸出

268787878787687

更新於: 29-6 月 -2020

114 次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.