Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Palindrome  RSS feed

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



Digits?
 
Marshal
Posts: 59681
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!