The divide
method of the BigInteger
class can divide the current BigInteger
object value by the passed BigInteger
value.
In Java, the
BigInteger
class handles vast integer mathematical operations outside the limits of all primitive types.
public BigInteger divide(BigInteger val)
This method takes a BigInteger
object as a parameter.
The divide
method returns a BigInteger
object. The value of the returned BigInteger
object is the division of the current BigInteger
value by the passed argument value.
The example below demonstrates how to use the divide
method:
import java.math.BigInteger;class BigIntegerDivideExample {public static void main( String args[] ) {BigInteger val1 = new BigInteger("246246");BigInteger val2 = new BigInteger("2");BigInteger result = val1.divide(val2);System.out.println(result);}}
BigInteger
class.import java.math.BigInteger;
BigInteger
objects, val1
with value 246246
and val2
with value 2
.BigInteger val1 = new BigInteger("246246");
BigInteger val2 = new BigInteger("2");
divide
method on the val1
object with val2
as an argument. This method call will return a BigInteger
that has a value equal to the division of val1
by val2
.BigInteger result = val1.divide(val2); //123123