//首先定义一个测试类
public class Main {
public static void main(String[] args) {
int[] ints = {11,24,35,41,52,66,71,82};
ErFen erFen = new ErFen();
int check = erFen.check(ints, 35);
System.out.println(check);
}
}
//具体实现
public class ErFen {
public int check(int[] a, int target) {
int i = 0;
int j = a.length;
while (i < j) {
int m = i + j >> 1;
if (target < a[m]) {
j = m;
} else if (target > a[m]) {
i = m + 1;
} else {
return m;
}
}
return -1;
}
}
控制台输出内容