@@ -0,0 +1,896 @@
+import java.io.FileReader;%0A%0Aimport com.google.gson.Gson;%0A%0Apublic class BinarySearch %7B%0A%0A%09public static int binarySearch(int key, int%5B%5D arr) %7B%0A%09%09int lo = 0;%0A%09%09int hi = arr.length - 1;%0A%09%09while (lo %3C= hi) %7B%0A%09%09%09int mid = lo + (hi - lo) / 2;%0A%09%09%09if (key %3C arr%5Bmid%5D) %7B%0A%09%09%09%09hi = mid - 1;%0A%09%09%09%7D else if (key %3E arr%5Bmid%5D) %7B%0A%09%09%09%09lo = mid + 1;%0A%09%09%09%7D else %7B%0A%09%09%09%09return mid;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return -1;%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) throws Exception %7B%0A%09%09BinarySearchInput%5B%5D inputs = new Gson().fromJson(new FileReader(%22binary-search/input.json%22), BinarySearchInput%5B%5D.class);%0A%09%09for (BinarySearchInput input : inputs) %7B%0A%09%09%09int r = binarySearch(input.key, input.array);%0A%09%09%09if (input.result != r) %7B%0A%09%09%09%09throw new Exception(%22binary search failed for: %22 + new Gson().toJson(input) + %22, actual: %22 + r);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09System.out.println(%22ok.%22);%0A%09%7D%0A%0A%7D%0A%0Aclass BinarySearchInput %7B%0A%09int key;%0A%09int%5B%5D array;%0A%09int result;%0A%7D%0A

add binary search of java code