Apparently Eclipse keeps giving me an error asking me to return an int. Is array[i] not considered an int or we cant return an index of a array in java like this? Anyone out there that can help me?
public static void main(String[] args){
int[] array = {10,6,4,3,12,19,18};
int z = quick_find_1d_peak1(array);
System.out.println(z);
}
public static int quick_find_1d_peak1(int[] inputArray){
for (int i=0 ; i<inputArray.length ; ){
if (i==0 && inputArray[i] >= inputArray[i+1]){
return inputArray[i];
} else if (i==inputArray.length && inputArray[i] >= inputArray[i-1]){
return inputArray[i];
} else if (inputArray[i] >= inputArray[i-1] && inputArray[i] >= inputArray[i+1]){
return inputArray[i];
} else {
i++;
}
}
}
elseclause will never be true, so the code there will never be executed. (Should it readi==inputArray.length-1 && ...instead?)