Assignment #5: Recursion
Winter 1999
(To be completed for your lab period February 8/9.)
Objective: To understand how recursion works.
Design, implement and test a Java program that reads a list of numbers and prints them in reverse order. The number 0 will end the list, and is not to be included in the output. Use recursion to reverse the list. Do not use an array or any other data structure that has not yet been discussed in class.
Hint: Design a method ``reverseNumbers'' that reads an integer and returns if it's 0; otherwise the method calls itself to process the other integers in the list and then prints the integer.Your code will look something like this:
public class Reverse {
static int promptInt (String prompt) {
System.out.print (prompt);
return Stdin.getInt ();
}
static void reverseNumbers () {
int i = promptInt ("Enter an integer: ");
// PUT YOUR CODE HERE
}
public static void main (String[] args) {
System.out.println ("Enter a list of integers, ending with 0.");
reverseNumbers();
}
}
Execution of the program should be similar to the example that follows.
The input supplied by the user is shown in bold.
Enter a list of integers, ending with 0.
Enter an integer: 8
Enter an integer: -2
Enter an integer: 3
Enter an integer: 0
3
-2
8

The goal is to find an interval
that is less than epsilon in length over which the function
changes sign (and hence must be equal to zero, the root, somewhere between
the two points).
The midpoint of the interval
If the sign change happens in the interval
then let
xRight = xMid, and similarly if the change is in the
other interval.
Then repeat the process.
Find an approximation to the equation