Homework 10: Palindrome Program
Objective: To write a program to determine if a word is a palindrome
A palindrome is a word that is spelled the same forward and backward, such as "radar", "madam", or "abba"
Your program should ask the user to enter a word, and then tell the user whether or not that word is a
palindrome.
- Your program doesn't need to determine whether or not the word is in the English language.
So for example your program would determine that the word "abcdefghijjihgfedcba" is a palindrome.
- You can assume that the word is made up of lower-case letters only.
- Please use at least two methods in addition to "main". For example, you may want
to write a method to input the word, and a boolean method to
determine if the string is a palindrome. Make sure to include comments with each method.
Also, declare all variables inside your methods (no class-level variables).
- Your program needs to include at least one loop, going through each character in the string.
Here is some sample output from the program:
Please enter a word: radar
The word you entered, 'radar' is a palindrome.
Please enter a word: abccba
The word you entered: 'abccba' is a palindrome.
Please enter a word: abcddxba
The word you entered: 'abcddxba' is not a palindrome.
Hint: To check to see if the last letter of a string named s is the letter 'e' you would write:
if(s.charAt(s.length()-1) == 'e')
For more notes and information on manipulating strings, see Chapter 2 part 2.
Return to main CS 111A page