08-06-2012, 11:28 PM
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]
[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]