Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 10:16:58 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: JAVA Palindrome Program  (Read 5194 times)

jeremejazz

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 58
  • hey!
    • View Profile
    • Personal Website
    • Donate to Member
JAVA Palindrome Program
« on: April 02, 2009, 05:46:00 AM »
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).rar


Sample Palindromes: :D

   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

jeremejazz

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 58
  • hey!
    • View Profile
    • Personal Website
    • Donate to Member
Re: JAVA Palindrome Program
« Reply #1 on: April 02, 2009, 05:55:42 AM »
I'll try to post the source file next time

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,367
    • View Profile
    • Donate to Member
Re: JAVA Palindrome Program
« Reply #2 on: April 02, 2009, 06:52:10 AM »
Wow!