public static int binarySearch(int a[], int value){
int left = 0;
int right = a.length - 1;
while (left <= right) {
int index = (left + right) / 2;
if (value < a[index]) {
right = right - 1;
} else if (value > a[index]) {
left = left + 1;
} else {
return index;
}
}
return -1;
}