import java.io.FileReader;

import com.google.gson.Gson;

public class BinarySearch {

	public static int binarySearch(int key, int[] arr) {
		int lo = 0;
		int hi = arr.length - 1;
		while (lo <= hi) {
			int mid = lo + (hi - lo) / 2;
			if (key < arr[mid]) {
				hi = mid - 1;
			} else if (key > arr[mid]) {
				lo = mid + 1;
			} else {
				return mid;
			}
		}
		return -1;
	}

	public static void main(String[] args) throws Exception {
		BinarySearchInput[] inputs = new Gson().fromJson(new FileReader("binary-search/input.json"), BinarySearchInput[].class);
		for (BinarySearchInput input : inputs) {
			int r = binarySearch(input.key, input.array);
			if (input.result != r) {
				throw new Exception("binary search failed for: " + new Gson().toJson(input) + ", actual: " + r);
			}
		}
		System.out.println("ok.");
	}

}

class BinarySearchInput {
	int key;
	int[] array;
	int result;
}

@@ -529,17 +529,21 @@
 .json%22),
- 
+%0A%09%09%09%09
 BinarySe
@@ -661,112 +661,199 @@
 %0A%09%09%09
-if (input.result != r) %7B%0A%09%09%09%09throw new Exception(%22binary search failed for: %22 + new Gson().toJson(input)
+System.out.println(%22binarySearch(%22 + input.key + %22, %22 + new Gson().toJson(input.array) + %22) =%3E %22 + r);%0A%09%09%09if (input.result != r) %7B%0A%09%09%09%09throw new Exception(%22failed. expected = %22 + input.result
  + %22
@@ -860,17 +860,18 @@
 , actual
-:
+ =
  %22 + r);
@@ -884,37 +884,8 @@
 %09%09%7D%0A
-%09%09System.out.println(%22ok.%22);%0A
 %09%7D%0A%0A

update java code