在 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP