Three objects are created.
There is just one reference variable, value
.
multiply()
Multiplication works as expected:
public BigInteger multiply( BigInteger val )
multiplyval
by theBigInteger
that contains the method. The result is returned in a newBigInteger
Here is a program:
import java.math.BigInteger; class AddSubtract { public static void main ( String[] args ) { BigInteger a = new BigInteger( "9" ); BigInteger b = new BigInteger( "12" ); BigInteger c = new BigInteger( "-20" ); BigInteger d = a.add( BigInteger.ONE ).multiply( b ).add( c ); System.out.println("Result: " + d ); } }
Result: 100
Arithmetic expressions with BigInteger
are sometimes not as nice as with the usual operators.
There are no precedence rules to help.
Read the above expression from left to right, performing the operations as they are encountered.
Each arithmetic operation creates a new object.
Evaluating the above expression creates three objects.
A reference to the last object is copied into the reference variable d
.
Which of the following, done with primitive int
s, corresponds to the above expression for d
?