Does remainder() sometimes return a zero?
Yes.
Here is a program that uses these methods:
import java.math.BigInteger;
import java.util.Scanner;
class RemainderDemo
{
public static void main ( String[] args )
{
Scanner scan = new Scanner( System.in );
String input;
BigInteger a, divisor, q, r;
System.out.print("a: ");
input = scan.next();
a = new BigInteger( input.trim() );
System.out.print("divisor: ");
input = scan.next();
divisor = new BigInteger( input.trim() );
q = a.divide( divisor );
r = a.remainder( divisor );
System.out.println( a + " divide " + divisor + " == " + q);
System.out.println( a + " remainder " + divisor + " == " + r);
System.out.println( q + " multiply " + divisor + " add " + r + " == "
+ (q.multiply(divisor)).add(r) );
}
}
C:\>java RemainderDemo
a: 17
divisor: 3
17 divide 3 == 5
17 remainder 3 == 2
5 multiply 3 add 2 == 17
C:\>java RemainderDemo
a: -17
divisor: 3
-17 divide 3 == -5
-17 remainder 3 == -2
-5 multiply 3 add -2 == -17
What do you suppose the following prints?
BigInteger A = new BigInteger( "18" );
BigInteger B = new BigInteger( "18" );
if ( A == B )
System.out.println("Trick Question");
else
System.out.println("Didn't fool me");
if ( A.equals( B ) )
System.out.println("Totally Expected");
else
System.out.println("Reference vs Object Confusion");