使用 Java 將一個 BigInteger 從另一個 BigInteger 中進行除法運算


使用 Java 中的 BigInteger divide() 方法將一個 BigInteger 從另一個 BigInteger 中進行除法運算。

首先,讓我們建立一些物件。

BigInteger one, two, three;
one = new BigInteger("200");
two = new BigInteger("100");

對以上進行除法計算並賦值到第三個物件 −

three = one.divide(two);

以下是一個示例 −

示例

 線上演示

import java.math.*;
public class BigIntegerDemo {
   public static void main(String[] args) {
      BigInteger one, two, three;
      one = new BigInteger("200");
      two = new BigInteger("100");
      // division
      three = one.divide(two);
      String res = one + " / " + two + " = " +three;
      System.out.println("Result: " +res);
   }
}

輸出

Result: 200 / 100 = 2

更新於: 2020 年 6 月 29 日

112 次觀看

開啟您的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.