public class BinarySearch {
public static int Search(int arr[], int value, int start, int end) {
int center = (start + end) / 2;
if (start <= end) {
if (value == center) {
return center;
}
if (value < center) {
return Search(arr, value, start, center - 1);
}
if (value > center) {
return Search(arr, value, center + 1, end);
}
}
return -1;
}
public static void main(String[] args) {
int arr[] = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int Index = Search(arr, 9, 0, arr.length);
if (Index == -1) {
System.out.println("Value Not Found");
} else {
System.out.println("Value found at Index: " + Index);
}
}
}