Nested loop extracting index values into new array
<p>I am trying to extract specific index values from an array, and place them into a new array. The primary array values are as follows:</p>

<pre><code> int a[] = {7, 8, 9, 9, 8, 7};
</code></pre>

<p>The call I am making to the method is as follows:</p>

<pre><code>print(findAll (a,7));
print(findAll (a,2));
</code></pre>

<p>The method I am using is as follows:</p>

<pre><code>public int[] findAll(int a[], int target)
    {
       int count = 0;
       int i = 0; 
       int index = 0;
       int spotIndex = 0;


       for (i = 0; i &lt; a.length; i++)
        {
          if (a[i] == target)
            count = count + 1;
            spotIndex = i;
        }        

        int result[] = new int[count];

        for (index = 0; index &lt; count; index++) 
        {
            result[index] = spotIndex;
            index++;

        }
        return result;
    } 
</code></pre>

<p>The results should be:</p>

<p>{0, 5}
{}</p>

<p>My results are below; if I change the target argument I get the same results.</p>

<p>{5, 0}
{}</p>

<p>Thanks in advance....</p>
