static void findPrimes(int n) {
        boolean[] primes = new boolean[n];

        for (int i = 2; i < n; i++)
            if (!primes[i])
                for (int j = i * i; j < primes.length; j += i)
                    primes[j] = true;

        for (int i = 2; i < primes.length; i++)
            if (!primes[i])
                System.out.println(i);

    }
This is finding prime numbers up to given number N. Space complexity is N.
The ides is to mark all numbers are divisible by i starting from 2 in every step.
src/algo/numerals/SieveofEratosthenes.java