public static int binarySearch(int i, int[] vals)
    throws Exception
  {
    int lb = 0;
    int ub = vals.length-1;
    int index = -1;

    while (lb <= ub)
      {
        int mid = (lb + ub) / 2;

        if (vals[mid] == i)
          {
            return index = mid; 
          } // if
        else if (vals[mid] < i)
          {
            lb = mid + 1;
          } // if
        else if (vals[mid] > i)
          {
            ub = mid - 1;
          } // if
      } // while
    if (lb > ub)
      {
        throw new Exception("The value doesn't exist in the array.");
      } // if
    return index;

  } // binarySearch