title: Java: Recursively search an array for an integer given an array, integer, and array length
body: <p>I'm trying to write a recursive method that accepts an int array, number of elements in the array, and an integer, and returns whether the integer is present as an element in the array.I just can't figure out why I this isn't working for all my test cases. Any help would be much appreciated!</p>
  
  <pre><code>public static boolean search(int[] findIn, int target, int len){
      if(len == 0){
          return false;
      }else if(findIn[len-1] == target){
          return true;
      }else{
          return search(findIn, target, len-1);
      }   
  }
  </code></pre>
  
  <p>Yes I realize there are better ways other than recursion to do this, but it is required that I do it this way.</p>
  
  <p>My main method looks like this: I'm just hard-coding it for the time being:</p>
  
  <pre><code>int[] arr = {1};
  System.out.println(search(arr,1,1));
  </code></pre>
  
  <p>Testcases:
  <img src="https://i.stack.imgur.com/7qb4Z.png" alt="enter image description here"></p>