BigInteger num1 = new BigInteger("123456789"); BigInteger num2 = new BigInteger("987654321"); BigInteger[] result = num1.divideAndRemainder(num2); System.out.println("Quotient: " + result[0]); System.out.println("Remainder: " + result[1]);
BigInteger num1 = new BigInteger("123456789"); BigInteger num2 = new BigInteger("987654321"); BigInteger[] result = num2.divideAndRemainder(num1); System.out.println("Quotient: " + result[0]); System.out.println("Remainder: " + result[1]);This code creates the same two BigIntegers as in Example 1, but divides the second by the first instead. The resulting quotient and remainder are printed out. The java.math.BigInteger class is a part of the standard Java library.