public class BinarySearchClass { static void BinarySearch(int[] InputArray, int InputTarget) { int index = -1; int lowEnd = 0; int highEnd = InputArray.length - 1; while (highEnd >= lowEnd) { int middle = (lowEnd + highEnd) / 2; if (InputArray[middle] == InputTarget) { index = middle; break; } else if (InputArray[middle] < InputTarget) { lowEnd = middle + 1; } else if (InputArray[middle] > InputTarget) { highEnd = middle - 1; } } if (index == -1) { System.out.println("Your target integer does not exist in the array"); } else { System.out.println("Your target integer is in index " + index + " of the array"); } } public static void main(String[] args) { //NOTE: The Array must be sorted ;-) int[] ExampleArray = {0, 1, 2, 4, 5, 8, 9, 10, 12, 14}; int ExampleTarget = 4; BinarySearch(ExampleArray, ExampleTarget); } }