Can somebody help me with this problem? It must use recursion however, and no iterative statements.
Write a method called reverse that takes a single long integer argument and returns the result of reversing its digits.
For example:
System.out.print(reverse(-12); returns -21
and
System.out.print(reverse(1234567)); returns 7654321
i know that (number % 10) gives the last digit and that (number / 10) gives the rest of the number, but i can't put it together. Here's what i got so far:
public static int reverse (int num)
{
if(num / 10 == 0)
return num;
return (reverse(num%10) * 10 ) + (num / 10);
}