O'Reilly logo

Java™ Puzzlers: Traps, Pitfalls, and Corner Cases by Neal Gafter, Joshua Bloch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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);    }}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required