package method;
public class Stest {
public static void main(String[] args) {
new Thread(new Sushu(2,100000)).start();
new Thread(new Sushu(100000,200000)).start();
}
}
package method;
/**
* 编写一个有两个线程的程序,第一个线程用来计算2~100000之间的素数的个数,
* 第二个线程用来计算100000~200000之间的素数的个数,最后输出结果
* @author Administrator
*/
public class Sushu implements Runnable{
public int i;
public int j;
public Sushu(int i, int j) {
this.i = i;
this.j = j;
}
@Override
public void run() {
int count=0;
int m,n;
for (m = i; m <=j; m++) {
for (n = 2; n < m; n++) {
if(m%n==0){
break;
}
}
if(m==n){
count++;
}
}
System.out.println(i+"~"+j+"之间素数为"+count+"个");
}
}