在 Java 中计算 BigInteger 的幂


在 Java 中使用 BigInteger pow() 方法来计算 BigInteger 的幂。

首先,让我们创建一些对象。

BigInteger one, two;
one = new BigInteger("5");

执行幂运算,并把它赋值给第二个对象 -

// power operation
two = one.pow(3);

以下是一个示例 -

示例

 实时演示

import java.math.*;
public class BigIntegerDemo {
   public static void main(String[] args) {
      BigInteger one, two;
      one = new BigInteger("5");
      System.out.println("Actual Value: " +one);
      // power operation
      two = one.pow(3);
      System.out.println("Result: " +two);
   }
}

输出

Actual Value: 5
Negated Value: 125

更新日期:2020 年 6 月 29 日

185 次浏览

开启您的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.