public static boolean linearSearch(int[] array, int target): This method should take as input an array of int
as well as an
int
. It should return
true
if the element
target
is present
in
array
. It should do so by examining each element of
array
one at a time sequentially starting
from the beginning of the array until the end. The method should return false if the element is not present.
public class ArrayUtilities{
public static void main(String[] args){
int[] array1= {1,2,3,4,5};
int target1 = 2;
linearSearch(array1,target1);
}
public static boolean linearSearch(int[] array, int target){
int x=0;
for(int i = 0; i< array.length; i++){
if(array[i] == target){
return true;
}
else{
x++;
}
}
if(x == 0){
return false;
}
return linearSearch;//**error here!**
}
}
Here is the code i wrote for this question. however i get a mistake at return linearSearch. I dont understand why. thank you in advance!
the mistake says: Symbol: variable linearSearch Location: class ArrayUtilities