File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Palindrome Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Palindrome" Watch "Palindrome" New topic
Author

Palindrome

Tarrell Fletcher
Ranch Hand

Joined: Oct 07, 2011
Posts: 60
Here is my code but I can't seem to get this phrase to output the same. The phrase is "A man a plan a canal panama"
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

Tarrell, I edited your code to use the "Code" tags. Looks a lot more readable, right? You can use them yourself in future, just click on the Code button and post your code between the tags you get.

Anyway, what exactly is your question? I would expect that code to output "This is not a Palindrome". Did it not do that? Or what were you expecting?
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Well, the result of reverseIt is: amanap lanac a nalp a nam A. Right away we are in trouble because the String.equals will fail as soon as it compares 'A' to 'a'. So your comparison needs to be case-insensitive. After you solve that, the String.equals will fail when it compares 'm' to ' '.

Note that palindromes ignore case, spaces, and punctuation. This celebrated palindrome is often rendered as: "A man, a plan, a canal: Panama!". So before you begin your String comparison, you'll want to strip out anything that is not a letter.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Dennis Deems wrote: So before you begin your String comparison, you'll want to strip out anything that is not a letter.


Digits?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Harsha Smith wrote: . . . Digits?
If you are using words, yes. You can have numbers which you regard as palindromic, eg 12321, but that is a different problem.
Tarrell Fletcher
Ranch Hand

Joined: Oct 07, 2011
Posts: 60
I found out how to fix it. I just needed to close up any whitespace so when I typed a word with a space it wouldn't see that blank. My assignment was to show the reversed code with no spaces so I guess that was it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Palindrome
 
Similar Threads
integer palindrome 'no strings'
Please help me on this palindrome program
Palindrome example
palindrome program
Question about Compilers and Methdods