title: return an array of prime numbers
body: <p>I need a method to return prime numbers in an array.</p>
  
  <p>So if given: primeArray(5)</p>
  
  <p>than an array like so should be returned: (2, 3, 5)</p>
  
  <p>For some reason this doesn't seem to work for me:</p>
  
  <pre><code>public static int[] primeArray(int numFind)
  {
      //determines the size of the array returned
      int primeTotal = 0;
  
      //loop to find total prime numbers
      for (int j = 1; j &lt;= numFind; j ++)
      {
          if (isPrime(j))
          primeTotal +=1;
      }
  
      //declare array to be returned
      int[] numA = new int[primeTotal];
  
      //current index of prime number
      int iP = 0;
  
      //loop to add prime elements to array
      for (int x = 1; x &lt;= numFind; x ++)
      {
          if (isPrime(x))
          {
              numA[iP]=x;
              iP++;    // &lt;--- THIS IS CAUSING ME PROBLEMS
          }
  
      }
  
      return numA;
  }
  
  public static boolean isPrime(int n)
  {
      for (int i = 2; i &lt; n; i++)
      {
          if(n%i==0)
              return false;
      }
      return true;
  }
  </code></pre>
  
  <p>This is what I'm using to test my code:</p>
  
  <pre><code>    int[] num = primeArray(11);
  
      System.out.println(num[0]);
      System.out.println(num[1]);
  </code></pre>
  
  <p>But for output I'm getting this:</p>
  
  <pre><code>1 
  2
  </code></pre>
  
  <p>If however I comment out the iP++; than the if statement finally decides to execute ONLY when prime numbers are passed as a parameter in: isPrime(j) but then if defeats the whole purpose of the primeArray method because I need the primeArray method to return an array of prime numbers.</p>