public static int binarySearch(int[] a, int num){ int low = 0; int high = a.length-1; while(low <= high) { int middle = (low + high)/2; if(num== a[middle]) { return middle; }else if(num<a[middle]) { high = middle - 1; }else { low = middle + 1; } } return -1; }