views:

21

answers:

2

Hello, 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.

+2  A: 

You use BigIntegers multiply() method like so:

BigInteger int1 = new BigInteger("131224324234234234234313");
BigInteger int2 = new BigInteger("13345663456346435648234313");
BigInteger result =  int1.multiply(BigInteger int2) 
jjnguy
If this gets too annoying, you can do work in Groovy which maps the operators correctly. I am implementing some math classes (BigRational for one) and for the first time Java has seemed extremely cumbersome--Although I generally love Java I have to admit that it's not the answer to every programming problem. If you need Java's speed but want advantages like Operator Overloading you might also try Scala.
Bill K
A: 

You can use the multiply(BigInteger) method in BigInteger. So:

BigInteger result = someBigInt.multiply(anotherBigInt);

BigInteger in Java API

swilliams