I have something error in my java code.. I'm trying to find the minimum number by recursion.. My error in last index.. I noted if the minimum number in last index I get error message "java.lang.ArrayIndexOutOfBoundsException: 8". otherwise, if the minimum number isn't in last index, it return the first minimum number found in the array and never check other values.
This is my code:
public static int minimumElement(int [] nums,int i){
if (i < nums.length && nums[i] < nums[i+1] )
return nums[i];
else
return minimumElement(nums, i=i+1);
}
Outputs