i want to get the user input from user and do non recursive binary search can any one show me how to do it it would be appreciated
public class Main {
// binarySeach: non-recursive
public int Main(int[] a, int x) {
int low = 0;
int high = a.length - 1;
while (low <= high) {
int mid = (low + high)/2;
if (a[mid] == x) return mid;
else if (a[mid] < x) low = mid + 1;
else high = mid - 1;
}
return -1;
}
public static void main(String[] args) {
Main bin = new Main();
int[] a =
{ 2, 8,12,14,16,19,24,28,31,33,// 0-9
39,40,45,49,51,53,54,56,57,60,// 10-19
63,69,77,82,88,89,94,96,97}; // 20-28
for (int i = 0; i < a.length; i++)
System.out.print(bin.Main(a,
a[i]) + " ");
System.out.println();
}
}