Hi, I have a javaproblem that I just can't solve.
"Write a recursive method who returns the largest value in an array with the signature:
public int max(int[] v)
(Hint: If you need to, use a private help-method)
It would be easy if it was allowed to change the signature so that it includes a counter, for example like this
public int max(int[] v)
int max(int [] v, int len)
{
int m;
if(len == 1)
return v[0];
else if(len == 2)
if(v[0] >= v[1]) {
return v[0];
}
else {
return v[1];
}
else{
m = max(v,len-1);
if (m >= v[len - 1]) {
return m;
}
else {
return v[len - 1];
}
}
}
}
But I can't do this. I would be really greatful if anyone cuold help me with this.