THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This post shows how to multiply BigIntegers in java with examples.
You can also check my previous posts on the BigInteger
class in java.
*
.The same does not work for BigInteger objects. It gives compilation error Operator ‘*’ cannot be applied to ‘java.math.BigInteger’, ‘java.math.BigInteger’.
Here is an example using the multiplication operator
import java.math.BigInteger;
public class BigIntegerMultiply {
public static void main(String[] args) {
BigInteger operand1= BigInteger.valueOf(2);
BigInteger operand2= BigInteger.valueOf(2);
BigInteger result=operand1*operand2;
System.out.println(result);
}
}
It provides a multiply
method to do multiplication on BigInteger.
The multiply
method returns the result of the multiplication of values.
BigInteger is immutable and the result of methods always returns a new object.
It internally uses an array of integers to do the process, The performance is less compared with Integer multiplication.
Syntax:
public BigInteger multiply(BigInteger val)
import java.math.BigInteger;
public class BigIntegerMultiply {
public static void main(String[] args) {
BigInteger operand1= BigInteger.valueOf(212312);
BigInteger operand2= BigInteger.valueOf(2123);
BigInteger result=operand1.multiply(operand2);
System.out.println(result);
}
}
Output:
450738376
🧮 Tags
Recent posts
Three dots in react components with example|Spread operator How to update ReactJS's `create-react-app`? Difference between super and super props in React constructor class? How to check the element index of a list or array in the swift example How to calculate the sum of all numbers or object values in Array swift with exampleRelated posts