把開發(fā)過程較好的內(nèi)容做個(gè)備份,下邊代碼段是關(guān)于Java版球1-n之間的素?cái)?shù)的代碼。
import java.util.ArrayList;
public class FindPrime {
public static void main(String[] args) {
double start? = System.currentTimeMillis() ;
ArrayList<Integer> PrameArray = new ArrayList<Integer>();
PrameArray.add(2);
PrameArray.add(3);
System.out.println("質(zhì)數(shù)如下");
System.out.println(2);
System.out.println(3);
int k=-1;
for (int n =5; n <100000000; ) {
int i;k++;
for ( i = 0; i < PrameArray.size(); i++) {
{PrameArray.add(n);
break;}
else if (n % PrameArray.get(i) == 0) {
break;
}
}
if(k%2==0)
? ? ? ? ? n+=2;
? ? ? ? ? ? else
}
double end? = System.currentTimeMillis() ;
System.out.println("程序運(yùn)行時(shí)間為"+(end-start));
}
}