BP Forums
Reversing Numbers - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19)
+---- Thread: Reversing Numbers (/showthread.php?tid=591)



Reversing Numbers - brandonio21 - 08-06-2012

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]


Re: Reversing Numbers - WitherSlayer - 01-05-2013

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.