在 Java 中计算 BigInteger 的幂
java 8object oriented programmingprogramming
使用 Java 中的 BigInteger pow() 方法计算 BigInteger 的幂。
首先,让我们创建一些对象。
BigInteger one, two; one = new BigInteger("5");
执行幂运算并将其分配给第二个对象 −
// 幂运算 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("实际值: " +one); //幂运算 two = one.pow(3); System.out.println("结果: " +two); } }
输出
实际值:5 取反值:125