Answer to Question #2155 in Java | JSP | JSF for Array method

Question #2155
Create a 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
value:10 theArray:{11, 3, 6, 7, 9, 60} ==> -1
1
Expert's answer
2011-03-29T12:35:10-0400
public static int findElementIndex(int fi, int[] arr){
for(int i = 0; i < arr.length; ++i)
if (arr[i] == fi)
return i;
return -1;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS