Description
Question 1 (10 points)
Write a program that starts by displaying the following menu:
- Reverse number
- Count Digits
- Repeat
- Exit
– – – – – – – – – – – – –
Enter a choice:
Choice 1 invokes a recursive method that takes as a parameter an integer, n, and returns another one with the digits reversed. For example, if n is 341, the method returns 143.
Choice 2 invokes a recursive method that takes as parameter an integer n and returns the number of digits in n. For example, if n is 67, the method returns 2.
Choice 3 invokes the recursive method repeat(String s, count n). The method creates and returns a new string s’ that is made by concatenating n copies of the parameter string s. For example, calling this method with the parameters “Object” and 3 would return the string “ObjectObjectObject”. If n is zero, the method should return the empty string.
Choice 4 terminates the program.
Any other choice, will have the menu displayed again.
Question 2 (10 points)
The program starts by prompting the user for numbers and stores them in an array. Then the following menu is displayed:
- Even or odd
- Find max
- Adds up
- Sum
- Exit
— – – – – – –
Enter your choice:
Choice 1 prompts the user whether he/she wants to print even or odd numbers in the array and invokes a method that prints those numbers if found in the array.
Choice 2 invokes a recursive method that displays the max in the array.
Choice 3 invokes a recursive method that returns true if we can split the array into two groups such that the sum of the numbers in one group is equal to that in the other group, false otherwise. For example, if the array is {3, 3}, the method returns true, if the array is {5, 10, 6, 3, 6}, the method returns true, if the array is {2, 4, 9, 10} the method returns false.
Choice 4 invokes a recursive method that accepts an array of integers and an int i as parameters. The method returns true if and only if we can choose numbers from the array such that the sum of these numbers is equal to i but no two adjacent numbers in the array are chosen.
Question 3 (not graded – but a very good exercise!) We have seen in class the recursive solution to the Towers of Hanoi problem. Write an iterative solution to the problem.
Notes
Since you do not need to create an object of the class to invoke any of the methods in the above exericses, you can declare all methods static. You can add as many parameters as needed to your methods. You can certainly find the solution to all questions online. If you look up the solutions, you will lose the chance of training and enhancing your problem-solving skills and you will not do well on the exam. Your choice!

