package bc;
import java.util.Scanner;
public class Binarysearch1 {
public static void main(String[] args) {
int[] list = { 11, 12, 13, 15, 19, 20 };
Scanner input = new Scanner(System.in);
System.out.print("Enter the number :");
int number = input.nextInt();
System.out.println("The position of" + " " + Binarysearch(list, 0, list.length - 1, number));
input.close();
}
private static int Binarysearch(int[] list, int low, int high, int number) {
while (high >= low) {
int mid = (low + high) / 2;
if (list[mid] == number) {
return mid;
}
if (list[mid] > number) {
return Binarysearch(list, low, mid - 1, number);
}
if (list[mid] < number) {
return Binarysearch(list, mid + 1, high, number);
}
}
return -1;
}
}