//recursive binary search on ints

public class BinSearch {

    public static int binarySearch(int a[], int value) {
	return recBinarySearch(a, value, 0, a.length-1);
    }
    
    protected static int recBinarySearch(int a[], int value, int low, int high) {
	if (low > high) {
	    return -1;
	} else {
	    //find midpoint
	    int mid = (low + high) / 2;
	    if (a[mid] == value) {
		return mid;
	    } else if (a[mid] < value) {
		//recurse on upper half
		return recBinarySearch(a, value, mid + 1, high);
	    } else {
		//recurse on lower half
		return recBinarySearch(a, value, low, mid - 1);
	    }
	}
    }

    public static void main (String args[]) {
	int [] a = {1, 3, 5, 6, 9};
	System.out.println(binarySearch(a, 3));
    }
}