7. Library Puzzlers

The puzzles in this chapter concern basic library-related topics, such as Object methods, collections, Date, and Calendar.

Puzzle 56: Big Problem

As a warm-up, test your knowledge of BigInteger. What does this program print?

import java.math.BigInteger;public class BigProblem {    public static void main(String[ ] args) {        BigInteger fiveThousand  = new BigInteger("5000");        BigInteger fiftyThousand = new BigInteger("50000");        BigInteger fiveHundredThousand                                 = new BigInteger("500000");        BigInteger total = BigInteger.ZERO;        total.add(fiveThousand);        total.add(fiftyThousand);        total.add(fiveHundredThousand);        System.out.println(total);    }}

Get Java™ Puzzlers: Traps, Pitfalls, and Corner Cases now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.