GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes integer palindrome 'no strings' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "integer palindrome Watch "integer palindrome New topic
Author

integer palindrome 'no strings'

billo bailey
Ranch Hand

Joined: Dec 02, 2002
Posts: 50
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


only users lose drugs
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dermot Curley
Ranch Hand

Joined: Jul 03, 2002
Posts: 43
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

Joined: Dec 10, 2001
Posts: 7023
Sure, objects are nice, but a simple a == b test would likely suffice.
Dermot Curley
Ranch Hand

Joined: Jul 03, 2002
Posts: 43
cant beat objects
well I had to make it a bit interesting !!
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
I think this does the trick:

Cheers, Neil
 
Don't get me started about those stupid light bulbs.
 
subject: integer palindrome 'no strings'