• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Palindorme no.

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks good. Here's a version that's simplified a bit

 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!