• 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

How to checker user enter is palindrome

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Appreciated if replies
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reading this is probably a good place to start - especially the first link.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Psychoh@cker please change your name in accordance with our Naming policies, thanks!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One hint: a word or sentence is a palindrome if it is the same after you reverse it. I'm sure you can find a method or set of methods to reverse a string.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another:

A word is a palindrome if its length is <= 1.
A word is a palindrome if its first and last characters are the same and the letters in between are a palindrome.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Martijn Verburg:
Psychoh@cker please change your name in accordance with our Naming policies, thanks!

Fyllikus? That's no better
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You obviously want your account closed; the naming policy is not optional. Change your displayed name.

CR
 
Phylisku
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can please show java code for check palimdrome
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Phylisku:
Can please show java code for check palimdrome



No
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the StringBuffer class (specially the reverse method)
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It had never occurred to me that you can do it recursively until I saw Garrett's method. Nice one!
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Garrett Rowe:
Another:

A word is a palindrome if its length is <= 1.
A word is a palindrome if its first and last characters are the same and the letters in between are a palindrome.



I like this...I've never heard of it before, only took me 12 lines of code including a try/catch and ending braces.

@ the OP. Take those 2 statements right there. Turn them into java code. If you come back with something written we'd be more than willing to help with specific questions. Most people don't want to help people who aren't willing to help themself.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
It had never occurred to me that you can do it recursively until I saw Garrett's method. Nice one!


You can even do it with a simple loop.

I did it in 11 lines, excluding try-catch (why would you need that?) with starting braces on new lines. Also no unncessary long lines (i.e. over 80 characters) or anything. I doubt it could be done any faster either.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
It had never occurred to me that you can do it recursively until I saw Garrett's method. Nice one!



Seriously? When I was being taught about data structures and algorithms one of the very first exercises used to familiarize us with the concepts of recursion was determining if a character string was palindromic. Somehow I've always thought of it as the universal textbook example of a recursive function. Weird
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think of Tower of Hanoi as the textbook recursion problem. But I'm sure there are others as well.

[Rob]: I did it in 11 lines, excluding try-catch (why would you need that?) with starting braces on new lines. Also no unncessary long lines (i.e. over 80 characters) or anything. I doubt it could be done any faster either.

I look at it as four lines of actual implementation, plus one line for a method declaration, plus as many lines of braces as your coding style requires. For me it's a six-line method, but others might well format it to ten lines. I expect we're talking about basically the same code though - perhaps the eleventh line is used capturing the length() in a variable?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the 11th line is used for counting the other lines to see whether it's shorter than everybody else's solution
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:

I did it in 11 lines, excluding try-catch (why would you need that?)


I'm sure yours is shorter, faster, stronger, amazinger, and wrote itself so I'm sorry.

I passed a substring into the same method after checking the first and last...if we substring from (1,1) on a substring of 2 length it's out of bounds. At this point you know it's a palindrome so I just caught it and returned true. Different strokes for different folks.

<psuedo>

</psuedo>

My point was that this didn't take long to do...from start to finish...mine was 12 lines including a try/catch that if I took the time to perfect the code the number of lines would decrease. He wasn't even attempting.
[ December 05, 2008: Message edited by: Paul Yule ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If is using ADT stack and queue.How would you do that? Show code
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Doe oeD:
If is using ADT stack and queue.How would you do that? Show code



"Doe oeD"
Please check your private messages for an important administrative matter
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And we don't just "show code".
reply
    Bookmark Topic Watch Topic
  • New Topic