aspose file tools*
The moose likes Beginning Java and the fly likes Palindorme no. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Palindorme no." Watch "Palindorme no." New topic
Author

Palindorme no.

Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105
Hi, I've created a programme to figure out is any number is palindrome or not by having a value at command prompt



But when I entered the value 994009, the compiler saying it is a palindrome no. why? Although it is doing fine, when I entered any other non-palindrome no., but why it is not doing the same with the above value?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
This seems odd:


Hint #1: You don't need "last" - it's the same as "e.length-1-start".

Hint #2: You don't need start to run from 0 to e.length-1. It's sufficient for start to run through e.length/2.
[ December 18, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Sunil Kumar
Ranch Hand

Joined: Apr 24, 2007
Posts: 76
That is because


This is because once second character is same as the last one. For any number like 9909, 6644446.. it will consider it as a palindrome.


Sunil Kumar
http://goodtoknowit.blogspot.com/
Sunil Kumar
Ranch Hand

Joined: Apr 24, 2007
Posts: 76
Further i am surprised to see the way you are saying yes or no.
There could be other ways. Create a method.Simply check for the equality condition, return no if it is unequal , return yes after the for loop completes
[ December 18, 2008: Message edited by: Sunil Kumar ]
Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105
Thanks, Ulf and Sunil. Could you please check, is the following is a correct way to write a palindrome code or not. Although this time it is working correct.


[ December 18, 2008: Message edited by: Pawan Arora ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
That looks good. Here's a version that's simplified a bit

Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105
Thanks Ulf.
 
Don't get me started about those stupid light bulbs.
 
subject: Palindorme no.