
What requirement is placed on an array, so that binary search may be used to locate an entry? â?º The array elements must form a heap. â?º The array must have at least 2 entries. â?º The array must be sorted. â?º The arrayâ??s size must be a power of two.

Here is an example that uses java in built function to search the location of particular array element.
import java.util.Arrays;
public class binary_search {
public static void main(String[] args) {
int ar1[]={2,44,5,66,78,90,23,66};
int p, key=78;
p=Arrays.binarySearch(ar1, key);
System.out.println("element found at index "+p);
Arrays.sort(ar1);
p=Arrays.binarySearch(ar1, key);
System.out.println("element found at index "+p);
}
}

Here is an example that implements binary search function and all the user to add elements to an array in order to search the location of particular array element.
import java.util.*;
public class BinarySearch {
public static void main(String[] args) {
int[] intArray = new int[10];
int searchValue = 0, index;
System.out.println("Enter 10 numbers");
Scanner input = new Scanner(System.in);
for (int i = 0; i < intArray.length; i++) {
intArray[i] = input.nextInt();
}
System.out.print("Enter a number to search for: ");
searchValue = input.nextInt();
index = binarySearch(intArray, searchValue);
if (index != -1) {
System.out.println("Found at index: " + index);
} else {
System.out.println("Not Found");
}
}
static int binarySearch(int[] search, int find) {
int start, end, midPt;
start = 0;
end = search.length - 1;
while (start <= end) {
midPt = (start + end) / 2;
if (search[midPt] == find) {
return midPt;
} else if (search[midPt] < find) {
start = midPt + 1;
} else {
end = midPt - 1;
}
}
return -1;
}
}