public class Search{ public static void main(String[] args) { int arr1[] ={1,3,5,6,8,10,13,15,19,23}; int i = 23; System.out.println(binarySearch(arr1,i)); } public static int binarySearch(int a[],int num) { int start = 0; int end = a.length - 1; int m = (end + start)/2; while(start<=end) { if(a[m] == num) { return m+1; } if(a[m] > num) { end = m-1; } if(a[m] < num) { start = m+1; } m = (end + start)/2; } return -1; } }