publicclassDemo{publicstaticintbinarySearch(int[] arr,int target){int left =0;int right = arr.length-1;while(left<=right){int mid =(left+right)/2;if(arr[mid]==target){return mid;}elseif(arr[mid]>target){
right = mid-1;// 向左查}else{
left = mid+1;// 向右查}}}}