Solutions to other chapters:
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  
Java Methods Home Page Skylight Publishing



Java Methods A & AB:
Object-Oriented Programming and Data Structures

Answers and Solutions to Exercises

Chapter 22

1.   010203010
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

10.   Proof.

Copyright © 2006 by Skylight Publishing