public class Binarysearchclass {public static int binary_search (int[] array, int value) {int is
Ginindex = 0;//low subscript int endindex = array.length-1;//high subscript int midindex =-1;
while (Beginindex <= endindex) {Midindex = Beginindex + (endindex-beginindex)/2;//Prevent overflow
if (value = = Array[midindex]) {return midindex;
else if (value < Array[midindex]) {endindex = midIndex-1;
else {beginindex = Midindex + 1;
}} return-1;
Found, return the subscript of the found value, not found, return-1}//start Tip: Automatic marking starting unique identification, do not delete or increase.
public static void Main (string[] args) {System.out.println ("Start ...");
int[] myarray = new int[] {1, 2, 3, 5, 6, 7, 8, 9}; System.out.println ("Find subscript for number 8:");
System.out.println (Binary_search (myarray, 8));
//end//Hint: Automatic marking end Unique identification, do not delete or increase. }