In Java, the BigInteger
class deals with very large integer values that the primitive data type can not represent.
The multiply
method of the BigInteger
class multiplies the passed BigInteger
object value with the called BigInteger
object value.
public BigInteger multiply(BigInteger val)
val
: This method takes a BitInteger
object as an argument that is to be multiplied.This method returns a BitInteger
object. The value of the returned BigInteger
object is the multiplication of the current BigInteger
value that calls the method and the passed argument value.
The example below demonstrates the use of the multiply
method:
import java.math.BigInteger;class BigIntegerMultiplyExample {public static void main( String args[] ) {BigInteger val1 = new BigInteger("123123");BigInteger val2 = new BigInteger("239857239562");BigInteger result = val1.multiply(val2);System.out.println(result);}}
In the code above,
BigInteger
class.import java.math.BigInteger;
BigInteger
objects val1
with the value 123123
and val2
with 239857239562
.BigInteger val1 = new BigInteger("123123");
BigInteger val2 = new BigInteger("239857239562");
multiply
method on the val1
object with val2
as an argument. This method call will return a BigInteger
, which has a value equal to the product of val1
and val2
.BigInteger result = val1.multiply(val2); //29531942906592126