Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reversing Numbers
#1
This method will return the reverse of a non-zero number
[code2=java]public static long ReverseNumber(long number)
{
int reversedNumber = 0;
while (number > 0)
{
reversedNumber *= 10; //Shift over the reversed number
reversedNumber += (int)(number % 10); //Add on the end of the submitted number
number/=10;
}

return reversedNumber;
}[/code2]
My Blog | My Setup | My Videos | Have a wonderful day.
#2
That's a lot easier than the video that you put on YouTube. That's probably because you were showing us 2 different ways to do it.


Forum Jump:


Users browsing this thread: 1 Guest(s)