public class ArrayTwoFindDemo1 { public static void main(String[] args) { int[] arr = {2,5,7,8,10,15,18,20,22,25,28}; int value = 18; int index = -1; int left = 0; int right = arr.length - 1; int mid = (right + left) / 2; while (left <= right){ System.out.println("范围是:" +left + "-->" + right); System.out.println("mid是:" + mid); if (arr[mid] == value){ index = mid; break; }else if (arr[mid] < value){ left = mid + 1; }else { right = mid - 1; } mid = (right + left) / 2; } if (index == -1){ System.out.println("你查找的数据不存在"); }else { System.out.println(); } } }