I am trying to create a method to search a sorted array for a value in the most efficient way possible. My teacher doesn't want us to use binary search yet. This is the code I have so far, is there any way to make it more efficient?
public int sortedSearch(int value) { for(int x=0;x<a.length; x++) if(a[x]<=value) { if(a[x]==value) return x; } return -1; } private int[] a;
Thank you.