A palindrome can be a single word, a verse, a sentence, a series of sentences, or a number that reads the same forward and backward. People have been creating palindromes in all languages since at as early as the third century BC*. Even today, they are still created with the help of all programming languages.
The Program So here's the palindrome program, written in JAVA. It lets the user input for a String and then tells the user if it is a palindrome or not. What you see there is just the main module of the program.
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Word or Sentence: ");
String temp_text = input.readLine().trim();
StringBuffer text = new StringBuffer(temp_text);
boolean test = (text.toString()).equalsIgnoreCase((text.reverse()).toString());
if(test)
{
System.out.println("Palindrome!");
}
else
{
System.out.println("Not a Palindrome");
}
I used the java.util.StringBuffer class in order to use the
reverse() method. Since palindromes aren't supposed to be case sensitive, I made use of the
equalsIgnoreCase() method.
The actual source code of the program is still under development
I've also included an applet version of this program just in case some of you don't have a Java Development Kit(JDK) but still have a Java Runtime Environment(JRE). Mozilla browsers usually have this program installed.
Palindrome(Applet).rarSample Palindromes: Can't think of a word or sentence? Try some of these suggested inputs:
123454321
Madam
Avid Diva
Dennis Sinned
Weakness There's just one problem I am trying to solve in this program. Palindromes aren't supposed to be affected by spaces and punctuation marks. This problem could be resolved by the java.util.StringTokenizer class since you can set it to ignore these delimiters. I will post an update as soon as I I get this successfully. I would appreciate your help in this difficult one.
*Desk Reference, the New York Public Library