BigInteger pow() in Java

pow(): This method is available in java.math.BigInteger class of Java.

Syntax:

BigInteger java.math.BigInteger.pow(int exponent)

This method takes one argument of type int as its parameter. This method returns a BigInteger whose value is (this exponent). 

Note: The exponent is an integer rather than a BigInteger.

Parameters: One parameter is required for this method.

exponent: exponent to which this BigInteger is to be raised.

Returns: this^exponent.

Throws: ArithmeticException - exponent is negative. (This would cause the operation to yield a non-integer value.)

For Example:

BigInteger bigInteger = new BigInteger("124")

int exponent = 23

bigInteger.pow(exponent) = > It returns 1408311607227967926219801595681358133797400346624.

Approach

Java

import java.math.BigInteger;

public class BigIntegerpow {
    public static void main(String[] args) {

        BigInteger bigInteger = new BigInteger("124");

        int exponent = 23;
        System.out.println(bigInteger.pow(exponent));
    }
}

Output:

1408311607227967926219801595681358133797400346624

No comments:

Post a Comment