Calculate the power on a BigInteger in Java


Use the BigInteger pow() method in Java to calculate the power on a BigInteger.

First, let us create some objects.

BigInteger one, two;
one = new BigInteger("5");

Perform the power operation and assign it to the second object −

// power operation
two = one.pow(3);

The following is an example −

Example

 Live Demo

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);
   }
}

Output

Actual Value: 5
Negated Value: 125

Updated on: 29-Jun-2020

149 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements