BigInteger pow() Method in Java Last Updated : 18 Feb, 2022 Comments Improve Suggest changes Like Article Like Report The java.math.BigInteger.pow(int exponent) method is used to calculate a BigInteger raise to the power of some other number passed as exponent whose value is equal to (this)exponent. This method performs operation upon the current BigInteger by which this method is called and exponent passed as parameter. Syntax: public BigInteger pow(int exponent) Parameter: This method accepts a parameter exponent which is the exponent to which this BigInteger should be raised to. Returns: This method returns a BigInteger which is equal to (this)exponent. Exception: The parameter exponent must be positive number (exponent >= 0) otherwise ArithmeticException is thrown. Examples: Input: BigInteger1=321456, exponent=5 Output: 3432477361331488865859403776 Explanation: BigInteger1.pow(exponent)=3432477361331488865859403776. 321456^5=3432477361331488865859403776 Input: BigInteger1=45321, exponent=3 Output: 93089018611161 Explanation: BigInteger1.pow(exponent)=93089018611161. 321456^5=93089018611161 Below programs illustrate pow() method of BigInteger class Example 1: Java // Java program to demonstrate // pow() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger b1; b1 = new BigInteger("321456"); int exponent = 5; // apply pow() method BigInteger result = b1.pow(exponent); // print result System.out.println("Result of pow operation between BigInteger " + b1 + " and exponent " + exponent + " equal to " + result); } } Output: Result of pow operation between BigInteger 321456 and exponent 5 equal to 3432477361331488865859403776 Example 2: Java // Java program to demonstrate // pow() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger b1; b1 = new BigInteger("12346"); int exponent = 6; // apply pow() method BigInteger result = b1.pow(exponent); // print result System.out.println("Result of pow operation between BigInteger " + b1 + " and exponent " + exponent + " equal to " + result); } } Output: Result of pow operation between BigInteger 41432345678 and exponent 6 equal to 5058679076487529899393537031261743031889730764186441745527485504 Example 3: Program showing exception when exponent passed as parameter is less than zero. Java // Java program to demonstrate // pow() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger b1; b1 = new BigInteger("76543"); int exponent = -17; try { // apply pow() method BigInteger result = b1.pow(exponent); // print result System.out.println("Result of pow operation between " + b1 + " and " + exponent + " equal to " + result); } catch (Exception e) { System.out.println(e); } } } Output: java.lang.ArithmeticException: Negative exponent Reference:https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/math/BigInteger.html#pow(int) Comment More infoAdvertise with us Next Article BigInteger pow() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-Functions java-math Java-BigInteger Java-math-package +2 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger modPow() Method in Java Prerequisite: BigInteger BasicsThe Java.math.BigInteger.modPow() method returns a BigInteger whose value is (thisexponent mod m ). If exponent == 1, the returned value is (this mod m) and if exponent < 0, the returned value is the modular multiplicative inverse of (this-exponent). The method thro 2 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read BigInteger xor() Method in Java Prerequisite: BigInteger Basics The xor(BigInteger val) method returns bitwise-XOR of two bigIntegers. This method returns a negative BigInteger if and only if exactly one of the current bigInteger and the bigInteger passed in parameter id negative. The xor() method of BigInteger class apply bitwise 2 min read BigInteger mod() Method in Java The java.math.BigInteger.mod(BigInteger big) method returns a BigInteger whose value is equal to (this BigInteger modfunction big(BigInteger passed as parameter)).In other words we can say that this method returns the value after performing (this % big) step.The mod operation finds the remainder aft 3 min read BigInteger sqrt() Method in Java java.math.BigInteger.sqrt() is an inbuilt function added in Java SE 9 & JDK 9 which returns BigInteger value of square root of a BigInteger on which sqrt() method is applied. It is the same as the floor(sqrt(n)) where n is a number. This Square root is less than the real square root if the real 2 min read BigInteger valueOf() Method in Java The java.math.BigInteger.valueOf(long value) method returns a BigInteger whose value is equal to value of long passed as parameter. This method is static method so It is not necessary to create object of BigInteger class to use this method.we can call this function by BigInteger.valueOf(long value) 2 min read BigInteger and() Method in Java The java.math.BigInteger.and(BigInteger val) method returns a BigInteger whose value is bitwise-AND of two BigIntegers. This method returns a negative number if both of the BigIntegers are negative. The and() method applies bitwise-AND operation upon the current bigInteger and bigInteger passed as p 2 min read BigInteger toString() Method in Java BigInteger Class offers 2 methods for toString(). toString(int radix): The java.math.BigInteger.toString(int radix) method returns the decimal String representation of this BigInteger in given radix. Radix parameter decides on which number base (Binary, octal, hex etc) it should return the string. I 3 min read BigInteger setBit() Method in Java The java.math.BigInteger.setbit(index) method returns a Big-integer whose value is equivalent to this Big-integer with the designated bit set. The method computes (this | (1<<n)). The bit at index n of binary representation of Big-integer will be set means converted to 1. Syntax: public BigInt 2 min read BigInteger testBit() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.testBit(index) method returns true if and only if the designated bit is set. This method Computes (this & (1<<n)) != 0). Syntax: public boolean testBit(int n) Parameter: The method takes one parameter n of integer type which refers 2 min read Like