I need to implement a recursive method printDigits that takes an integer num as a parameter and prints its digits in reverse order, one digit per line.
This is what
Here you go :
static String reverseDigits(int n) { String N = ""; if ( n== 0) return N; else { N += n%10; return N + reverseDigits(n/= 10); } }
This is of course returned as String.
If you want it as int all you have to do is parse it using Integer.parseInt()
Integer.parseInt()