Note: Version 2, below, uses the Sieve of Eratosthenes. There are several answers that helped with what I originally asked. I have chosen the Sieve of Era
public static void primes(int n) { boolean[] lista = new boolean[n+1]; for (int i=2;i