//二分查找,前提数组必须是有序的
int[] arr = new int[]{-1,0,1,5,7,9,11,15};
int target = 10;
int head = 0;
boolean is = true;
int end = arr.length-1;
while (head<=end){
int middle = (head+end)/2;
if (target ==arr[middle]){
System.out.println("找到了,索引为"+middle);
is = false;
break;
}else if (target>arr[middle]){
head = middle+1;
}else {
end = middle-1;
}
}
if (is){
System.out.println("没找到");
}