public static void main(String[] args) { int v = 1; int[] a = {1,2,3,4,5}; int left = 0; int right = a.length - 1; while (left <= right) { int mid = (left + right) / 2; if (a[mid] >= v) { right = mid - 1; } else { left = mid + 1; } } System.out.println(left + 1); }