June 2005
Beginner to intermediate
312 pages
6h 24m
English
All the puzzles in this chapter concern loops.
This program loops through the byte values, looking for a certain value. What does the program print?
public class BigDelight { public static void main(String[ ] args) { for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) { if (b == 0x90) System.out.print("Joy!"); } }}
The loop iterates over all the byte values except Byte.MAX_VALUE, looking for 0x90. This value fits in a byte and is not equal to Byte.MAX_VALUE, so you might think that the loop would hit it once and print Joy! on that iteration. Looks can be deceiving. If you ran the program, ...