next up previous
Next: About this document ... Up: Assignment 8: Strings and Previous: Dupledromity

A few more string things

1.
Write a method called printReverse that takes a String and prints it backwards, all on one line, with a newline at the end.

This method can be done either iteratively or recursively. I find the iterative version easier.

2.
Write a method called reverse that takes a String and that returns a String that contains the same letters, but backwards. This method should not print anything. For example, if the argument is "Allen", the return value should be "nellA".

This method can be done either iteratively or recursively. I find the recursive version easier.

3.
The Captain Crunch decoder ring works by taking each letter in a string and adding 13 to it. For example, 'a' becomes 'n' and 'b' becomes 'o'. The letters ``wrap around'' at the end, so 'z' becomes 'm'.

Write a method that takes a String and that returns a new String containing the encoded version. You should assume that the String contains upper and lower case letters, and spaces, but no other punctuation. Lower case letters should be tranformed into other lower case letters; upper into upper. You should not encode the spaces.

4.
Generalize the Captain Crunch method so that instead of adding 13 to the letters, it adds any given amount. Now you should be able to encode things by adding 13 and decode them by adding -13. Try it.


next up previous
Next: About this document ... Up: Assignment 8: Strings and Previous: Dupledromity
Allen B. Downey
1999-03-31