• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Palindrome

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic