public static int[] Eratosthenes(int maxPrimeNumber) {

    // Define new vector A with all numbers from 2 to N
    int[] vectorA = new int[maxPrimeNumber + 1];
    for (int index = 2; index <= maxPrimeNumber; index++) {
      vectorA[index] = index;
    }

    int nonPrimeCount = 0;
    // Flag all non-primes in vector A.
    int sqrtMaxPrime = (int) Math.sqrt(maxPrimeNumber);
    for (int index = 2; index < sqrtMaxPrime; index++) {
      // Skip this number if known composite
      if (vectorA[index] != 0) {
        int composite = index * index;
        // Flag all composites of this number as non-prime
        while (composite <= maxPrimeNumber) {
          if (vectorA[composite] != 0) {
            vectorA[composite] = 0;
            nonPrimeCount++;
          }
          composite = composite + index;
        }
      }
    }
    // Create new array from A, filled with just primes.
    int resultIndex = 0;
    int[] primes = new int[maxPrimeNumber - nonPrimeCount - 1];
    for (int index = 2; index <= maxPrimeNumber; index++) {
      if (vectorA[index] != 0) {
        primes[resultIndex++] = vectorA[index];
      }
    }
    return primes;
  }