Display numeric value in reverse order

Example: given a number say 7584, the program should display it in reverse order 4857.

public class Reverse
{
public static void main(String args[])
{
int i = 7584;
Reverse r = new Reverse();
r.reverseNum(i);
}

public void reverseNum(int num)
{
if(num!=0)
{
System.out.print(num%10);
num = num/10;
reverseNum(num);
}
}
}

Rate this post

Leave a Reply