1:项目结构
2:代码
package tianyi.demo3;
public class hang extends Thread{
int i,j,x=0;
hang(int m,int n){
this.i = m;
this.j = n;
}
public void run() {
int p,q;
p=0;q=0;
for(int m=i;m<=j;m++) {
for(int h=1;h<=m;h++) {
q=m%h;
if(q==0)p=p+1;
}
if(p==2) {
x=x+1;
}
p=0;
}
System.out.println("输出"+i+"到"+j+"之间的质数个数:"+x);
}
public static void main(String[] args) {
hang thread1 = new hang (2,100000);
hang thread2 = new hang (100000,200000);
thread1.start();
thread2.start();
}
}
3:结果展示