next up previous
Next: Something useful Up: Assignment 4: Recursion Previous: A little number theory

A little String manipulation

  1. Download, compile and run:

    http://rocky.wellesley.edu/cs230/code/hw04/Test.java
  2. In Test.java, fill in isDoubloon as described on the exam. You should write a helper method named makeLetterHistogram. Use it to find all the doubloons in /usr/dict/words.
  3. A palindrome is a word that reads the same both forward and backward, like ``otto'' and ``palindromeemordnilap.'' An alternative, recursive definition of a palindrome is ``either an empty string or a word whose first letter is the same as the last, and whose middle is a palindrome.''

    Write a recursive method named isPalindrome that takes a String and that returns a boolean indicating whether the word is a palindrome or not. Print all the palindromes in the dictionary.

    It would be an excellent idea to write helper methods called first (which returns the first letter of a String), last (which returns the last letter of a String), and middle (which uses subString and returns all but the first and last characters, or an empty string if there are none).



Allen Downey
Tue Oct 3 11:14:12 EDT 2000