使用 Java 將一個 BigInteger 乘以另一個 BigInteger
BigInteger 類用於進行原始資料型別之外的大整數計算。它為模運算、GCD 計算、素數測試、素數生成、位操作以及一些其他雜項操作提供了操作。
若要將一個 BigInteger 乘以另一個 BigInteger,請使用 BigInteger multiply() 方法。
首先,讓我們建立一些物件 −
BigInteger one, two, three; one = new BigInteger("2"); two = new BigInteger("8");
將以上物件相乘並將其分配給第三個物件 −
three = one.multiply(two);
以下是一個示例 −
示例
import java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, two, three; one = new BigInteger("2"); two = new BigInteger("8"); three = one.multiply(two); String res = one + " * " + two + " = " +three; System.out.println("Multiplication: " +res); } }
輸出
Multiplication: 2 * 8 = 16
廣告