Win a copy of Microservices in Action this week in the Web Services forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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: 23889
50
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: 61819
193
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!