class Main {
public static int binarySearch(int[] arr, int k) {
int low = 0;
int high = arr.length - 1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == k) {
return mid;
} else if (arr[mid] < k) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return -1;
}
public static void main(String[] args) {
int[] arr = {6, 17, 25, 34, 52, 63, 85};
int target = 6;
int result = binarySearch(arr, target);
if (result != -1) {
System.out.printf("元素 %d 在数组中的位置是:%d\n", target, result);
} else {
System.out.printf("元素 %d 不在数组中\n", target);
}
}
}