package Learn;
public class Cha {
public static int ChaZhao (int a,int []nums) {
int b=nums.length;
if(b==0) {
return 0;
}
int left=0;
int right=b-1;
while(left<right) {
int mid=left+right/2;
if(nums[mid]==a) {
return mid;
}
else if(nums[mid]<a){
left=mid+1;
}
else {
right=mid;
}
}
return right;
}
public static void main(String [] args) {
int arr[]= {1,2,3,4,5,6,7,8};
int c=3;
System.out.println(ChaZhao(c,arr));
}
}
09-03