本帖最后由 feigecal 于 2012-6-18 23:29 编辑
class ChaZhao
{
public static void main(String[] args)
{
int [] arr={2,4,6,7,9,};
int a=chaZhao(arr,8);
System.out.println(a);
}
public static int chaZhao(int[] arr,int key)
{
int min,max,mid;
min=0;
max=arr.length-1;
mid=(min+max)/2;
while(min<=max)
{
if (arr[mid]<key)
min=mid+1;
else if(arr[mid]>key)
max=mid-1;
else
return mid;
}
return -1;
}
}
搞了半天还没搞明天为什么编译没错,但运行却没有结果 |