next up previous
Next: A few more string Up: Assignment 8: Strings and Previous: Exam question

Dupledromity

1.
Write a recursive method called isDupledrome that take a String as an argument and that returns a boolean indicating whether the word is a dupledrome.

Think about whether there are any helper methods like first, last and middle that will make this program easier to write. What are the preconditions for the helper methods?

2.
Test your method extensively to make sure it works for all words, even weird ones like the empty string. Using the Guardian Pattern, see if you can ``prove'' that it is impossible for your method to cause an exception.

3.
Write an iterative version called isItDupledrome. Be careful not to get the recursive and iterative versions confused. They will look very different. I find it useful to draw a picture of the string and the indices.



Allen B. Downey
1999-03-31