It only uses the prime numbers to check if the other numbers are also prime
static public int[] primeGen(int a){
int[] series={2};
if (a==1 || a==2 || a<=0){
return series;
}
this is where the errors occur
else{
boolean Prime = false;
for (int i = 3; i<=a; i++){
boolean[] state = {};
for (int j = 0; !(state[state.length-1]) && (j<series.length); j++){
state = Arrays.copyOf(state, state.length +1);
state[state.length -1] = i % series[j] ==0;
}
for (int k = 0; (Prime) && (k<state.length); k++){
Prime = !(state[k]);
}
if (Prime){
series = Arrays.copyOf(series, series.length +1);
series[series.length -1] = i;
}
}
return series;
}
}
Sorry if I just made a rookie mistake, cause I've been learning Java for 3 days now