Solutions Manual for Data Structures
and Algorithms in Java, 6e Michael
Goodrich, Roberto Tamassia (All
Chapters)
, Chapter
Java Primer
1
Hints and Solutions
Reinforcement
R-1.1) Hint Use the code
templates provided in the Simple
Input and Output section.
R-1.2) Hint You may read about cloning in
Section 3.6.
R-1.2) Solution Since, after the
clone, A[4] and B[4] are both
pointing to the same GameEntry
object, B[4].score is now 550.
R-1.3) Hint The modulus operator could be
useful here.
R-1.3) Solution
public boolean isMultiple(long n, long m) {
return (n%m == 0);
}
R-1.4) Hint Use bit operations.
R-1.4) Solution
public boolean isEven(int i) {
return (i & 1 == 0);
}
,https://www.stuvia.com/user/papersprime
R-1.5) Hint The easy solution uses
a loop, but there is also a formula
for this, which is discussed in
Chapter 4.
R-1.5) Solution
public int sumToN(int n) {
int total = 0;
for (int j=1; j
<= n; j++)
total += j;
return total;
}
,