I have a problem want to solve. I have an array of integers from which I want to get the minimum integer. I have also been given a function definition which am supposed to adhere to. I am not supposed to use a loop or a static variable in my solution. How can I solve this? Here is my function.
public static int findMin(int[] numbers, int startIndex, int endIndex){}
Please assist. I have tried this implementation with a loop.
public static int findMin(int[] numbers, int startIndex, int endIndex) {
int min = 0;
for (int count = startIndex; count <= endIndex; count++) {
if (numbers[count] < min) {
min = numbers[count];
}
}
return min;
}
Arrays.asList(numbers).stream().min(Integer::compareTo).get();