Java Method For Reversing a Number

Reversing a number is such a common thing when you are programming. How to do so in Java? have a look at the given code:

int REV(int n){
long Temp,RevNumber=0;
Temp=n;
while (Temp>0) // till temp > 0 continue to perform the loop
{
RevNumber=(RevNumber*10)+(Temp%10);
// RevNumber is multiplied by 10 and added to the
// remainder of temp divided by 100
Temp=Temp/10;
}
return  (int) RevNumber;
}

Leave a Reply

Make sure you tick the "Notify Me" box below the comment form to be notified of follow up comments and replies.