RHS =>  Allan =>  Basic Programming => Exercises => Palindrome Updated:  02/02/2004 23:36
WebMaster: allanhn@rhs.dk

Palindrome

A palindrome is a string that is the same (except for the space between words) whether you read it forwards or backwards (e.g. "otto", "a toyota" or "ed is on no side").

You can check if a string is a palindrome by


Question 1

Create a worker class, Palindrome, with a string-variable str (with set- and get- methods) and a method, isPalindrome(), that checks if str is a palindrome and returns the boolean result.

Create an application class, PalindromeApp, that creates a Palindrome object and then tests different strings (sets the value in the object to be the string you want to test and then perform the test using isPalindrome())

A good way to check if your program works is to write both strings (with all spaces removed) to the screen - it's easy to spot any difference