Java Reference
In-Depth Information
< Day Day Up >
Puzzle 95: Just Desserts
Most of the puzzles in this chapter were quite challenging. This one isn't. What does each of the
following programs print? The first two were reported as platform bugs, if you can believe it [Bug
4157460, 4763901]:
public class ApplePie {
public static void main(String[] args) {
int count = 0;
for (int i = 0; i < 100; i++); {
count++;
}
System.out.println(count);
}
}
import java.util.*;
public class BananaBread {
public static void main(String[] args) {
Integer[] array = { 3, 1, 4, 1, 5, 9 };
Arrays.sort(array, new Comparator<Integer>() {
public int compare(Integer i1, Integer i2) {
return i1 < i2 ? -1 : (i2 > i1 ? 1 : 0);
}
});
System.out.println(Arrays.toString(array));
}
 
 
Search WWH ::




Custom Search