Java says ''the type of the expression must be Array type but it resolved to Int"
I'm looking to do a nested For Loop for the solution, but any other more more elegant suggestions are also welcome.
public class ArraySearch {
public static int searchForItemInArray(int needle, int[] haystack) throws Exception {
for (int i = 0; i <= needle; i++) {
for (int j = 0; j < haystack.length; j++) {
if (needle[i] == haystack[j]) {
}
}
}
return -1;
}
}
needle is an Int variable so isn't part of an array.
The answer to fix the IF statement was
needle == haystack[j]