class Demo
{
public static void main(String[] args)
{
int [] arr ={1,2,4,5,6,8,9,10};
int position = binary(arr,11);
System.out.println("position="+position);
}
public static int binary(int[] arr,int a)
{
int min,max,mid;
min=0;
max=arr.length-1;
mid=(min+max)/2;
while (arr[mid]!=a)
{
if (a>arr[mid])
min=mid+1;
else if(a<arr[mid])
max=mid-1;
if (min>max)
return -1;
mid=(min+max)/2;
}
return min;
}
}