在 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