• 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

Need a method for recognizing a pallindrome

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does any one have a coded method that will recognize a pallindrome within a String (same string whether backwards or forwards, i.e. BOB, MOM, DAD)?
[ March 19, 2004: Message edited by: Douglas Braxton ]
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one solution :
use reverse() method inside StringBuffer class
then compare the result with the original string.

Originally posted by Douglas Braxton:
Does any one have a coded method that will recognize a pallindrome within a String (same string whether backwards or forwards, i.e. BOB, MOM, DAD)?
[ March 19, 2004: Message edited by: Douglas Braxton ]

 
Douglas Braxton
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you elaborate? i cannot get the compiler to recognize reverse().
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
post your code, we discuss from there !

Originally posted by Douglas Braxton:
can you elaborate? i cannot get the compiler to recognize reverse().

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Douglas,
This is a great recursive problem. You method would check if the first and last characters of the string were the same, if so, create a new string consisting of the second through second to last characters of the string and recursively call your method with the new string.
Now for the base case. If the string is null, it's not a pallindrone. If the string is one character long, it's obviously a pallindrone. If it's two characters long, and the characters are the same, it's a pallindrone.
Post some code, and you'll get some more help. Most of the cowboys around these parts, don't like to post code when the problem appears to be homework related but we are more than happy to help once you've made an attempt.
Hope this helps,
Tom Blough
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do they still use that one as the standard homework assignment for recursion???
 
Douglas Braxton
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this one figured out. its an end to end comparison as noted. IGNORE the white space and compare apples to apples. or put differently
String s1 = " ";
is a different animal than
char s1 = ' ';
thanks everybody!!!
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With weiss.nonstandard, it should look something like this pseudo code:

[ March 22, 2004: Message edited by: Gabriel White ]
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what if you tried something like:
 
Parth Sagdeo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, you could use the trim() method for cutting out excess spaces
 
author
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I would do...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic