Use the below given code to reverse a number in Java.
Code:
Number after reverse :54321
Code:
public class ReverseNumber {
public static void main(String args[])
{
System.out.println("Number after reverse :"+reverseNum(12345));
}
public static int reverseNum(int num)
{
int reverse=0;
while(num>0)
{
reverse=reverse*10 + num%10;
num=num/10;
}
return reverse;
}
}
Output :Number after reverse :54321
No comments:
Post a Comment