- p183, Chapter 3, Exercise 3 -
For the third example case, printPowersOfN(-2,8) the output should be: 1 -2 4 -8 16 -32 64 -128 256. The book lists 32 in that sequence as positive, but should be negative.
(Thanks to Joe Hubbard)
- p184, Chapter 3, Exercise 9 (distance) -
For the second example case, distance(10, 2, 3, 5) the result should be 7.615773105863909. The book lists the answer as 14.7648230602334.
The other way to fix this is to change the call to distance(10, 2, 3, 15) which will give an output of 14.7648230602334.
(Thanks to Joe Hubbard)
- p264, Chapter 4 -
The first line of code should read:
product *= i;
(Thanks to Alan Fowler of University of Washington Tacoma)
- p287, Chapter 4 -
In the first paragraph, the word "width" should be "weight". ...(such as the user’s height, weight, or BMI)...
(Thanks to Dan Zera of North Seattle Community College)
- p370, Chapter 5, Exercise 9 -
Exercise 5.9 says at the end, "Your method should print nothing if the empty string (
""
) is passed."
But this text does not make sense for this problem, because the method accepts an int
parameter, not a string.
This text should be disregarded.
(thanks to Richie Sweeney)
- p487, Chapter 7 -
Line 38 of the program doesn't have enough spaces between the columns. It should read:
System.out.println("Digit Count Percent");
(Thanks to Alan Fowler of University of Washington Tacoma)
- p496, Chapter 7, Exercise 6 (stdev) -
The standard deviation formula is slightly incorrect. It should have the "squared" exponent outside the rightmost parenthesis. The overall formula should be:
(Thanks to Alan Fowler of University of Washington Tacoma)
- p626, Chapter 9, Exercise 9.12 - Cash.equals -
In one place, says "Stock" where it should say "Cash".
(Thanks to Martizzle Stizzle)
-
p675, Chapter 10, Exercise 10.11 - stutter - This problem is a duplicate of Exercise 10.4:
doubleList
. The problem description should be the following:
Write a method stutter
that takes an ArrayList
of String
s and an integer k as parameters and that replaces every string with k copies of that string. For example, if the list stores the values ["how", "are", "you?"]
before the method is called and k is 4, it should store the values ["how", "how", "how", "how", "are", "are", "are", "are", "you?", "you?", "you?", "you?"]
after the method finishes executing. If k is 0 or negative, the list should be empty after the call.
(Thanks to Daniel King, who is a ninja)
-
p697, Chapter 11 - The code for the
totalElements
method has an error. The line that calls contains
should read:
if (!set1.contains(element)) {
(Thanks to Doug Trenkamp)
-
p708, Chapter 11 - Line 38 of the code shown is missing a "not" (!) symbol. It should read:
if (!wordCountMap.containsKey(word)) {
(Thanks to Dana Van Aken of Bellevue College)
- p722, Chapter 11 -
Line 25 of the Lottery program should be:
double prize = PRIZE * Math.pow(2, matches.size());
(Thanks to Chris Middleton of Boston University)
- p771, Chapter 12, Exercise 12.16, Figure 12.8 -
The Cantor Set 3rd row down is drawn wrong; should be split into thirds:
(Thanks to Jeff Matocha of Ouachita Baptist University)
- p825, Chapter 14 -
A sentence in the middle of the page mistakenly refers to the
showConfirmDialog
method of class JOptionPane
when it should refer to showInputDialog
. The sentence should read, "One limitation of JOptionPane
is that its showInputDialog
method always returns the user's input as a String
."
(Thanks to Son Nguyen of Seattle Central Community College)
- p977, Chapter 16 -
Exercise 2 is to write toString and exercise 3 is to write indexOf, but that code already appears on pages 954-955 of the book. So this is a poorly chosen exercise.
(Thanks to Stewie Regal)
- p1030, Chapter 17 -
Exercise 1 is to write a sum method, but that code already appears on page 1002. So this is a poorly chosen exercise.
(Thanks to Stewie Regal)
- p1030, Chapter 17 -
The example output for Exercise 7 is backward. It should be:
leaves: 9 4 0
(Thanks to Frannie)
- p1047, Appendix A -
The solution to Self-Check 4.1, problem (i) should be:
Math.abs(y) % 10 == Math.abs(y)
(Thanks to Andreas Asterlund)
- p1057, Appendix A -
The solution to Self-Check 5.7 should be:
Random rand = new Random();
int num = rand.nextInt(25) * 2 + 51;
(Thanks to Alan Fowler of University of Washington Tacoma)
- p1135, Appendix D -
In a few places on this page, we refer to the "homework" package, but it should be the "homework4" package for consistency.
(Thanks to Technical University of Denmark professor, Jørgen Villadsen)
- p1148, Index -
The index entry of pages containing "printf" should read:
printf
statements, 253, 257, 259-261
(Thanks to Alan Fowler of University of Washington Tacoma)