public class Solution { public int binarySearch(int[] R,int k) { int mid; int i=0; int j=R.length-1; while(i<=j) { mid=(i+j)/2; if(R[mid]>k) { j=mid-1; }else if(R[mid]<k) { i=mid+1; }else { return mid; } } return -1; } public static void main(String[] args) { Solution s=new Solution(); int[] R={3,6,9,13,15,16,17,23,35,56}; int result=s.binarySearch(R,23); System.out.println(result); } }