go to previous page   go to home page   go to next page highlighting

Answer:

0


compareTo( BigInteger other )

compareTo( BigInteger other ) implements the Comparable interface and works as with other classes.

It returns -1, 0 or 1 when this BigInteger is numerically less than, equal to, or greater than other.

For example,

(new BigInteger( "11" )).compareTo( new BigInteger( "28" ) )  // returns -1

(new BigInteger( "28" )).compareTo( new BigInteger( "28" ) )  // returns 0

(new BigInteger( "55" )).compareTo( new BigInteger( "28" ) )  // returns 1

Think of a minus sign between the left operand and the right operand:

11 - 28

However, the value returned is always one of -1, 0, or +1.


QUESTION 17:

What is the output of the following?

BigInteger A = new BigInteger( "3000000000" );
BigInteger B = new BigInteger( "4000000000" );

if ( A.compareTo( B ) < 0 )
  System.out.println( "A is less than B" );
else
  System.out.println( "A is not less than B" );

go to previous page   go to home page   go to next page