I need to make a recursive function that returns the number of digits in the array.
This is what I got so far
public static int Rec(int[] arr, int size)
{
int numbers = 0;
if(size > 0)
{
numbers = String.valueOf(arr[size]).length() + Rec(arr, size-1); //length of digits in array
}
return numbers;
}
But the problem is that it crashes the debug when it gets there.
I think it is the String.valueOf
that makes it crash, any ideas on how I could get the number of digits in x-th place of the array? (number of digits in arr[x]
)