class ErFenFa
{
public static void main(String[] args)
{
int low=0,high=arry.length-1, mid;
int [] arry1={1,3,7,34,56,98};
int erfenfa(int[] arry,int key)
{
while(low<=high)
{
mid=(low+high)/2;
if(arry[mid]>key)
high=mid-1;
else if(arry[mid]<key)
low=mid+1;
else
return mid;
}
return -1;
}
System.out.println(erfenfa(arry1,7));
}
}
|
|