title: Problems with counting in a recursive function without adding a parameter (Java)
body: <p>I apologize if this has been answered already but the only answers I could find involved adding a parameter called count.</p>
  
  <p>My assignment asks us to count the number of items in a linked list using recursion. </p>
  
  <p>Here is what I tried (note I am using an array because I have one created and I have a lot more to do tonight:</p>
  
  <pre><code>public static int countArray(int[] array, int first, int last)
  {
      int count;
  
      if(first &lt; last)
      {
          countArray(array, first + 1, last);
      }
  
      return (count + 1);
  }
  </code></pre>
  
  <p>This, as expected, returns 2 even though the length of the array is 10. I have also tried setting count to 1 but that just resets it (also as expected) every time the function is called. I am sure there is something obvious I am missing but I just can't figure out what it is. Thanks!</p>