• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

integer palindrome 'no strings'

 
billo bailey
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
howdee there,
i'm a rookie and stuck on a problem. I need to write a program without the use of strings or arrays that works out if a number is a palindrome or not. I've got the number to reverse by % and /
but need to reconstruct it so I can compare the two numbers, what i've been trying to do is to find the number of digits in the number and using a loop multiply the corresponding digits by the appropriate number, ie 10,100,1000 etc. Any help would be great.
billo 'darn tootin' bailey
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, billo!
What part of this problem are you stuck on? Feel free to post relevant example code - just be sure to surround it with the [code] and [/code] UBB Tags.
 
Dermot Curley
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billo, not sure if I have this straight, you have the two ints but you want to convert the new value back to the original to compare them ?? Why not just create 2 new Integer objects and use the int compareTo(Integer anotherInteger) method to do the compare for you?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, objects are nice, but a simple a == b test would likely suffice.
 
Dermot Curley
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cant beat objects
well I had to make it a bit interesting !!
 
Neil Laurance
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this does the trick:

Cheers, Neil
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic