public static void main(String[] args) { int target = 10; int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int startI = 0; int endI = a.length - 1; while (startI <= endI) { int mid = (startI + endI) / 2; if (a[mid] == target) { break; } if (a[mid] < target) { startI = mid + 1; } if (a[mid] > target) { endI = mid - 1; } } }