Answers to Self-Review Exercises

6.1
  1. method call.

  2. local variable.

  3. return.

  4. void.

  5. top.

  6. last-in, first-out (LIFO).

  7. return; or return expression; or encountering the closing right brace of a method.

  8. Random.

  9. activation record, stack frame.

  10. stack overflow.

  11. scope.

  12. method overloading.

  13. method call.

6.2
  1. class body.

  2. block that defines method rollDice’s body.

  3. class body.

  4. class body.

  5. block that defines method play’s body.

6.3The following solution demonstrates the Math class methods in Fig. 6.2:
 1 // Exercise 6.3: MathTest.java
 2 // Testing the Math class methods.
 3
 4 public class MathTest
 5 {
 6    public static void main( String args[] )
 7    {
 8       System.out.printf( "Math.abs( 23.7 ) = %f\n", Math.abs( 23.7 ) );
 9       System.out.printf( "Math.abs( 0.0 ) = %f\n", Math.abs( 0.0 ) ...

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.