二分查找法是用于查找一个数字在一个有序序列中的位置 public class BinarySearch { public static int bsearch(int[] array,int findData) { int low = 0; int high = array.length-1; while (low<high) { int mid = (low+high)/2; if (findData>array[mid]) { low = mid+1; }else if (findData<array[mid]) { high = mid-1; }else if (findData == array[mid]) { return mid; } } return -1; } public static void main(String[] args) { int[] arr = { 6, 12, 33, 87, 90, 107, 209, 878 }; System.out.println("87的脚标是:" + (bsearch(arr, 87))); } } 结果:87的脚标是:3