class Main {
public static boolean binarySearch(int[] arr, int tar) {
int left = 0;
int right = arr.length - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (arr[mid] == tar) {
return true;
} else if (arr[mid] < tar) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return false;
}
public static void main(String[] args) {
int[] arr = {85, 63, 52, 34, 25, 17, 6};
int tar = 6;
boolean result = binarySearch(arr, tar);
if(result){
System.out.println( tar + "在数组中存在。" );
}else{
System.out.println( tar + "在数组中不存在。");
}
}
}