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

更新于: 29-06-2020

400 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始学习
广告