DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: JAVA Palindrome Program  (Read 8,961 times)

jeremejazz

  • hey!
  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 59
JAVA Palindrome Program
« on: April 02, 2009, 10:46 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.

Code
	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

  • hey!
  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 59
Re: JAVA Palindrome Program
« Reply #1 on: April 02, 2009, 10:55 AM »
I'll try to post the source file next time

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • Cody Award
    • Official Forum Clown
    • rotten turkey sandwich - Rotten Turkey Sandwich
Re: JAVA Palindrome Program
« Reply #2 on: April 02, 2009, 11:52 AM »
Wow!
Chris

Original address: https://www.donationcoder.com/forum/index.php?topic=17736.0