当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Java Java.math.BigInteger.pow()用法及代码示例


描述

这个java.math.BigInteger.pow(int exponent)返回一个 BigInteger,其值为 (thisexponent)。 index 是整数而不是 BigInteger。

声明

以下是声明java.math.BigInteger.pow()方法。

public BigInteger pow(int exponent)

参数

exponent- 此 BigInteger 将被提升到的 index 。

返回值

此方法返回一个 BigInteger 对象,其值为 thisexponent

异常

ArithmeticException− index 为负。这将导致操作产生非整数值。

示例

下面的例子展示了 math.BigInteger.pow() 方法的用法。

package com.tutorialspoint;

import java.math.*;

public class BigIntegerDemo {

   public static void main(String[] args) {

      // create 2 BigInteger objects
      BigInteger bi1, bi2;

      // create and assign value to exponent
      int exponent = 2;

      // assign value to bi1
      bi1 = new BigInteger("6");

      // perform pow operation on bi1 using exponent
      bi2 = bi1.pow(exponent);

      String str = "Result is " + bi1 + "^" +exponent+ " = " +bi2;

      // print bi2 value
      System.out.println( str );
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Result is 6^2 = 36

相关用法


注:本文由纯净天空筛选整理自 Java.math.BigInteger.pow() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。