
946 CHAPTER 13 Recursion
13.2 Recursion with a Return Value
In the preceding example, we coded a very simple method. Now let’s look at
some examples that are a little more complex, with recursive methods that
return a value.
In a value-returning method the return statement can include a call to
another value-returning method, as in:
public static int multiplyAbsoluteValueBy3( int n )
{
return ( 3 * Math.abs( n ));
}
In this case, the multiplyAbsoluteValueBy3 method cannot return its value
until the abs method returns a value, allowing the expression in the return
statement to be fully evaluated.
The same principle applies to a value-returning method that ...