title: Recursive binary search in an int array using only 1 parameter
body: <p>How can i implement a recursive binary search in an int array using only 1 parameter in java ?
  it tried but my code doesn't work. I implemented a class which its instances are objects having arrays and a count variable to detect how many elements are their in the array. any idea how can i implement the recursive binary search using only 1 parameter ?</p>
  
  <pre><code>public class LinearSortedArray {
      int count;
      int[] a;
  
      public LinearSortedArray() {
          count = 0;
      }
  
      public LinearSortedArray(int size) {
          count = 0;
          a = new int[size];
      }
  
      public static int[] copyingMethod(int startPoint, int endPoint,
              LinearSortedArray arrayObj) {
          int[] copyingArray = new int[endPoint - startPoint];
          int j = startPoint;
          for (int i = 0; i &lt; copyingArray.length; i++) {
              copyingArray[i] = arrayObj.a[j];
              j++;
          }
          return copyingArray;
      }
  
      public int binarySearchRec(int x) {
          if (count == 0) {
              return -1;
          }
          int pivot = count / 2;
          LinearSortedArray newArrayObj;
          if (x &gt; a[pivot]) {
              newArrayObj = new LinearSortedArray(count - pivot);
              newArrayObj.count = newArrayObj.a.length;
              newArrayObj.a = copyingMethod(pivot, count, this);
  
              for (int i = 0; i &lt; newArrayObj.a.length; i++) {
                  System.out.print(newArrayObj.a[i]);
                  System.out.print(" ");
              }
              System.out.println();
              return pivot + newArrayObj.binarySearchRec(x);
          } else if (x &lt; a[pivot]) {
              newArrayObj = new LinearSortedArray(pivot);
              newArrayObj.count = newArrayObj.a.length;
              newArrayObj.a = copyingMethod(0, pivot, this);
              for (int i = 0; i &lt; newArrayObj.a.length; i++) {
                  System.out.print(newArrayObj.a[i]);
                  System.out.print(" ");
              }
              System.out.println();
              return newArrayObj.binarySearchRec(x);
          } else {
              return pivot;
          }
      }
  }
  </code></pre>
  
  <p>P.S.: The arrays are already sorted</p>