publicclassPrimeNumber{
privateintcount=0;
privateintn;
//用于判斷一個數是不是素數
publicbooleanjudge(intnumber){
for(inti=2;i<=Math.sqrt(number);i++){
if(number%i==0){
returnfalse;
}
}
returntrue;
}
//用于處理某一范圍的數據
publicvoidhandle(intstartNumber,intendNumber){
for(inti=startNumber;i<=endNumber;i++){
if(this.judge(i)==true){
this.count++;
}
}
}
publicvoidshow(){
System.out.println("count="+count);
}
}
=====================================================================
packagebbb;
publicclassPrimeNumberTest{
publicstaticvoidmain(String[]args){
PrimeNumberpn=newPrimeNumber();
pn.handle(101,200);
pn.show();
}
}