java
public class Main{
public static void main(String[] args){
int[] arr={10,20,30,40,50,60,70};
int i =20;
System.out.println(binarySearch(arr,i));
}
public static int binarySearch(int[] arr,int number){
int min =0;
int max=arr.length-1;
while(true){
if(min>max){
return -1;
}
int mid=(min+max)/2;
if(arr[mid]>number){
max=mid-1;
} else if (arr[mid]<number) {
min = mid+1;
}else{
return mid;
}
}
}
}