Java – How to calculate of Power of a BigInteger Number ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem Statement

You need to calculate the power of a number of type BigInteger in Java.

Solution

Use the instance method “pow” of the type BigInteger by passing the exponent which will return the power as shown below.

import java.math.BigInteger;

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

        BigInteger input1 = new BigInteger("2987569");
        int exponent = 3;
        BigInteger result = input1.pow(exponent);
        System.out.println(result);
    }

}


The output of the above program is

26665751846889541009

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: