The Question: Create a static method called findElementIndex, which takes an integer and an integer array as input parameters, and returns the smallest index where that value appears. If the value is not in the array, the method should return -1. Example: value: 3 theArray:{10, 3, 6, 3, 8, 10} ==> 1 or value: 10 theArray:{11, 3, 6, 7, 9, 60} ==> -1
public static int findElementIndex (int value, int [ ] theArray)
{ }
My code: Will not compile & I think i've looked at it too many times to notice a mistake.
int index = 0;
int n = -1;
for(int i =0; i < theArray.length; i++)
if(value == theArray[i]) {
index = i;
return index;
}
else {
return n;
}
Thank you.