Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)

16.7 Exercises

  1. Write a recursive method to print the square of n natural numbers.

  2. Write a recursive method to print n natural numbers that are even.

  3. Write a recursive method to print all letters in a string in reverse order, that is, if the string is "Java," it will print "avaJ."

  4. Write a recursive method that will reverse a given string, that is, it will convert "hello" to "olleh."

  5. Write a recursive method that will compute the factorial of n natural numbers.

  6. A palindrome is a string that does not change when it is reversed. For example: "madam," "radar," and so on. Write a recursive method that checks whether a given string is a palindrome.

  7. Design and implement a program that includes a recursive method for a linear search in an array of integer values. For a review on the principles of linear searches, see Section 9.4.3.1.

  8. Design and implement a program that includes a recursive method for a binary search in an array of integer values. For a review on the principles of binary searches, see Section 9.4.3.2.

Категории