class AddDemo
{
public static void main(String[] args)
{
int[] arr = {2,4,6,8,12,24,35,46,56};
int i = add(arr, 11);
System.out.println("index="+i);
}
public static int add(int[] arr, int key)
{
int min = 0;
int max = arr.length-1;
int mid = (min+max)/2;
while (mid<=max)
{
mid = (min+max)/2;
if (key<arr[mid])
{
max = mid-1;
}
else if (key>arr[mid])
{
min = mid+1;
}
else
return mid;
}
return min;
}
}
请问这个程序的运行结果为什么是0?
|
|