Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using BigInteger Multiply operator

I was wondering if there was a way to multiply BigInteger variables together, because the * operator cannot be applied to BigInteger.

So I was wondering if it was possible to multiply two BigIntegers together without using the * operator.

like image 639
Steffan Harris Avatar asked Oct 06 '10 23:10

Steffan Harris


People also ask

How do you use the BigInteger operator?

You can not use the operators on BigInteger . They are not primitives like int , they are classes. Java has no operator overloading.

How does BigInteger divide work?

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.


1 Answers

You use BigIntegers multiply() method like so:

BigInteger int1 = new BigInteger("131224324234234234234313");
BigInteger int2 = new BigInteger("13345663456346435648234313");
BigInteger result =  int1.multiply(int2) 

I should have pointed out a while ago that BigInteger is immutable. So any result of an operation has to be stored into a variable. The operator or operand are never changed.

like image 99
jjnguy Avatar answered Oct 12 '22 06:10

jjnguy