title: Find the first n prime numbers and store them in an array
body: <p>I need to find the first <code>n</code> <em>prime numbers</em> and store them in the array <code>primes</code>. With the help of stuff I found on stackoverflow I succeeded in find the first <code>n</code> numbers, but when I try to store them in the array, I get the <code>ArrayIndexOutOfBoundsException</code>...</p>
  <pre class="lang-java prettyprint-override"><code>public static int[] firstNPrimes(int n) {
      int[] primes = new int[n];
      int ncounter = 0;
      int isPrime = 2;
      for (int i = 0; ncounter &lt; n; i++) {
          boolean prime = true;
          for (int j = 2; j &lt; isPrime; j++) {
              if (isPrime % j == 0) {
                  prime = false;
                  break;
              }
          }
          if (prime) {
              primes[i] = isPrime;
              ncounter++;
          }
          isPrime++;
      }
      return primes;
  }
  </code></pre>