I'm trying to understand recursion by doing some codes. This code should find the maximum number in the array recursively, but for some reason it doesn't work. Thanks for your help!
public static void main(String[] args) {
int array [] = {11,4,6,9,15,2};
maxNum(array, 1, 0);
}//Main
public static int maxNum(int array[], int maxIndex, int i)
{
int ans;
if(i==array.length-1) //Condition Stop
{
ans= maxIndex;
}
else
{
ans= maxNum(array, Math.max(array[maxIndex], array[i]), i++);
}
System.out.println(array[maxIndex]);
return ans;
}//maxNum
}//Class