Here:
for(int n = 2; y < 1000; n++){
y = n * x;
numbers[y] = false;
}
you first check that y < 1000
, and then intialize and use it. This is the wrong way around.
Also, you can get away with running the above loop only when x
is prime. This won't affect correctness, but should make your code much faster.