for(i=2;i<n;i++){ // for(int j=i+1;j<n;j++){ if(a[j]!=0&&a[j]%i==0) { // System.out.println("the jjj is "+a[j]); a[j]=0; // System.out.println("the jjj is "+a[j]); // System.out.println("the i is "+i); // System.out.print("@"+j+"---"+"\n"); } else { // System.out.print("the a[j] is "+a[j]); // if(a[j]>b[s-1]){ //这里之所以错,是因为凡是不被2整除的都放进来了 // b[s]=a[j]; // System.out.print("the s is "+s+"-"+b[s]+"\n"); // s++; // continue; } } } int t=0; for(int k=0;k<n;k++){ if(a[k]!=0){ t++; System.out.println("-"+k+"-"+a[k]+"-"); } } System.out.println("-the total number of primer number is "+t+"-"); }
}
运行结果(当N=10时) -1-1- -2-2- -3-3- -5-5- -7-7- -the total number of primer number is 5-