- Write a recursive method to add up the integers from 1 to N (where N is passed in as a
parameter).
- Write a recursive method to add up the contents of an array of doubles.
- The Towers of Hanoi problem (Google it!) can be solved by the following recursive
algorithm ...
if you want to move only one disk {
just do it, and print the move
} else if you want to move N disks {
move N-1 disks from the "from" pile to the "spare" pile
move one disk from the "from" pile to the "to" pile
move N-1 disks from the "spare" pile to the "to" pile
}
Write a recursive Java method to implement this algorithm.
- Does the following recursive method get into infinite recursion? Why?
public static void doNumbers(int number) {
System.out.println(number);
if (number % 2 == 0) {
doNumbers(--number);
} else {
doNumbers(number/2 + 1);
}
}
- What's the output from the following program?
[an error occurred while processing this directive]