Java Software Structures, 4th Edition Exercise Solutions, Ch. 8
Chapter 8 Exercise Solutions
EX 8.1 Write a recursive definition of a valid Java identifier.
A Java-Identifier is a: Letter
or a: Digit followed by a Java-Identifier-Substring
EX 8.2 Write a recursive definition of xy (x raised to the power y), where x and y are
integers and y > 0.
x1 = x
EX 8.3 Write a recursive definition of i * j (integer multiplication), where i > 0. Define
the multiplication process in terms of integer addition. For example, 4 * 7 is
equal to 7 added to itself 4 times.
1 * j = j
EX 8.4 Write a recursive definition of the Fibonacci numbers, a sequence of integers,
each of which is the sum of the previous two numbers. The first two numbers
in the sequence are 0 and 1. Explain why you would not normally use recursion
to solve this problem.
Fib(0) = 0
EX 8.5 Modify the method that calculates the sum of the integers between 1 and N
shown in this chapter. Have the new version match the following recursive
definition: The sum of 1 to N is the sum of 1 to (N/2) plus the sum of (N/2 + 1)
to N. Trace your solution using an N of 7.
// Computes the sum of the numbers between n1 and n2 (inc)
public int sum (int n1, int n2)