使用 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
广告