Calculate 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: 2020-06-29T05:24:05+05:30

222 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements