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 6

1. (a) Invalid declaration of local variables: different types should be separated by a semicolon, not a comma.
(b) OK field
2. (d) T -- it is often desirable to give the same name to variables that hold the same types of values for similar purposes in different methods.
(e) F -- unfortunately the compiler assumes that the code is correct and that the name refers to the local variable where that variable is defined.
5.   compiled
6. (a) 0
(c) 5.0
7. (a) 105
11.   double d = Math.sqrt((double)b * b - 4.0 * a * c); double x1 = 0.5 * (-b - d) / a; double x2 = 0.5 * (-b + d) / a;
12.   Should be double temp;
18.   See JM\Ch06\Exercises\Solutions\DogsHumanAge.java.

Copyright © 2006 by Skylight Publishing