i haved coded and there is no error in the code…but still, it is not printing the correct value
public class binarysearch {
public static void main(String[] args) {
int [] array = {23,12,53,456,76,445,34,65,45,334,434,3,24,343,43,45,65};
System.out.println(binary(array,76));
}
public static int binary(int []arr, int item)
{
int low = 0;
int high = arr.length-1;
while(low<=high)
{
int mid = (low+high)/2;
if(arr[mid]<item) {
low = mid+1;}
else if(arr[mid]>item) {
high = mid-1;}
else {
return mid;}
}
return -1;
}
}