I'm trying to implement a java code to test linear search on a sorted array and this is my code
public class ArrayTest {
public static void main(String [] args) {
int []x= {12,8,6,23,6,5,17,20,9};
int y =linearSearch(x,23);
}
public static int linearSearch(int []ar,int value) {
int searchedIndex=-1;
for(int i=0;i<ar.length;i++) {
if (ar[i]==value) {
searchedIndex=i;
break;
}
}
return searchedIndex ;
}
}
The problem is that this doesn't generate any output also no errors were generated. Can anyone explain the reason for this.