Solutions to other chapters:
Java Methods A & AB:
Object-Oriented Programming and Data Structures
Answers and Solutions to Exercises
Chapter 22
3. |
|
009
display prints all the digits of a
number except the most significant digit.
|
6. |
|
public boolean isDivisibleBy9(int n)
{
if (n < 9)
return false;
else if (n == 9)
return true;
else
return isDivisibleBy9(sumDigits(n));
}
|
7. |
(a) |
pow(x, n) executes n - 1
multiplications.
It is easy to prove this fact using mathematical induction.
Therefore, this version is no more economical
than a simple for loop.
The answer is 4. |
9. |
|
100
mysterySum(n) returns n2.
Indeed, (n-1)2 + 2*n - 1 = n2
|
|