title: How do you recursively count the number of negative numbers in an array (Java)?
body: <p>I need to use this method:</p>
  
  <pre><code>public static int countNegative(double[] numbers, int count){ }
  </code></pre>
  
  <p>to count the number of negative numbers in a double array. I could easily do it if I could include a 3rd parameter, sum, but I can only use the array and an int. I'm completely stuck. I've tried a few things, but cannot get it right. I've gotten everything from the size of the array to ArrayIndexOutOfBounds, but never the right answer. Could anyone help me out with this?</p>
  
  <p>-EDIT-</p>
  
  <p>Well here is the exact assignment:</p>
  
  <blockquote>
    <blockquote>
      <p>Write a program that reads in a sequence of numbers (not necessary integers) from standard input until 0 is read, and stores them in an
      array, similar to what you did in assignment 2. This part is done
      using iteration . You may assume that there will not be more than 100
      numbers.</p>
    </blockquote>
    
    <p>Then compute the maximum number stored in the array, the count of
    negative numbers, and compute the sum of positive numbers, using
    recursion. Thus you will create recursive methods findMax, 
    countNegative, and computeSumPositive in Assignment9 class and they
    will be called by a main method.</p>
    
    <p>Specifically, the following recursive methods must be implemented
    (These method should not contain any loop):</p>
  
  <pre><code>public static double findMax(double[] numbers, int count)  -&gt; It finds the maximum number in the array, count is the number of elements
  </code></pre>
    
    <p>in the array</p>
    
    <p>public static int countNegative(double[] numbers, int count) ->
    counts the negative integers</p>
    
    <p>public static double computeSumPositive(double[] numbers, int count)
    -> sums number of positive integers</p>
  </blockquote>
  
  <p>findMax() was easy:</p>
  
  <pre><code>public static double findMax(double[] numbers, int count){
          if(numbers.length - 1 == count)
              return numbers[count];
          else 
              return Math.max(numbers[count], findMax(numbers, count+1));
      }
  </code></pre>
  
  <p>This is my most recent attempt at countNegative. It just returns 99 (I have the array initialized with 100 elements):</p>
  
  <pre><code>public static int countNegative(double[] numbers, int count){
          int i=0;
          if(numbers[count]&lt;0)
              i=1;
          if(numbers.length-1==count)
              return count;
          else
              return i+countNegative(numbers,count+1);
       }
  </code></pre>
  
  <p>I should be able to figure out the computeSumPositive if I can figure out this negative one.</p>
  
  <p>Count can be whatever you need it to be. I used it more as an index in findMax.</p>