@@ -0,0 +1,2499 @@
+package binarysearch;%0A%0Aimport java.util.Scanner;%0Aimport static java.util.Arrays.sort;%0A%0Apublic class BinarySearch%0A%7B%0A  /**%0A   *  Fills given array with random values.%0A   *%0A   *  @param array    the array%0A   *  @param maxValue the maximum allowed value%0A   */%0A  private static void fillWithRandomValues(int%5B%5D array, int maxValue)%0A  %7B%0A    int length = array.length;%0A%0A    for (int i = 0; i %3C length; i++)%0A      array%5Bi%5D = (int)(Math.random() * maxValue);%0A  %7D%0A%0A  /**%0A   *  Prints the program's help text.%0A   */%0A  private static void printHelpText()%0A  %7B%0A    System.out.println(%22Usage:%5Cn%22 +%0A                       %22java binarysearch.BinarySearch ARRAY_SIZE MAX_VALUE%5Cn%22 +%0A                       %22%5CtARRAY_SIZE - The size of the array%5Cn%22 +%0A                       %22%5CtMAX_VALUE  - The maximum value allowed in the array%22);%0A  %7D%0A%0A  /**%0A   *  Performs a binary search for the given key in the array.%0A   *%0A   *  @param array the array to search in%0A   *  @param key   the searched value%0A   *  @param min   lowest index%0A   *  @param max   highest index%0A   *%0A   *  @return      the position of the key in the array, if found, otherwise -1.%0A   */%0A  public static int binarySearch(int%5B%5D array, int key, int min, int max)%0A  %7B%0A    if (max %3C min)%0A      return -1;%0A%0A    int midpoint = (min + max) / 2;%0A%0A    if (array%5Bmidpoint%5D %3E key)%0A      return binarySearch(array, key, min, midpoint - 1);%0A    else if (array%5Bmidpoint%5D %3C key)%0A      return binarySearch(array, key, midpoint + 1, max);%0A    else%0A      return midpoint;%0A  %7D%0A%0A  public static void main(String%5B%5D args)%0A  %7B%0A    if (args.length %3E 1)%0A    %7B%0A      try%0A      %7B%0A        int arraySize = Integer.parseInt(args%5B0%5D),%0A            maxValue  = Integer.parseInt(args%5B1%5D);%0A%0A        if (arraySize %3E 0)%0A        %7B%0A          int array%5B%5D = new int%5BarraySize%5D;%0A%0A          fillWithRandomValues(array, maxValue);%0A          sort(array);%0A%0A          for (int value : array)%0A            System.out.print(value + %22 %22);%0A%0A          System.out.println(%22%22);%0A          %0A          Scanner scanner = new Scanner(System.in);%0A%0A          int key = 0;%0A          while ((key = scanner.nextInt()) %3E -1)%0A          %7B%0A            System.out.println(%22Found key at position: %22 + %0A                               binarySearch(array, key, 0, arraySize - 1));%0A          %7D%0A        %7D%0A        else%0A          System.err.println(%22Array size can not be negative!%22);%0A      %7D%0A      catch (Exception e)%0A      %7B%0A        System.err.println(e);%0A        e.printStackTrace();%0A      %7D%0A    %7D%0A    else%0A      printHelpText();%0A  %7D%0A%7D%0A

Implement recursive binary search algorithm