I want to separate each digit of a number by a recursive function. I am trying the following function:
private static void print( int n ){
print( n/10, n%10 );
}
private static int print( int n, int ld ){
if( n < 10 ) return n;
int digit = n % 10;
int first = print( n/10, ld );
System.out.println( digit );
return first;
}
But it does not work. Can anyone help me how can I change the above function to achieve my outcome ?
input : 12345 output: 1 2 3 4 5
I want to do this by a recursive function