**
输出任意两个数之间的所有素数
**
import java.util.Scanner;
public class Prime {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("下限:");
int n = scan.nextInt();
System.out.println("上限:");
int m = scan.nextInt();
for(int i=n;i<=m;i++){
if(isPrime(i)){
System.out.print(i + " ");
count++;
if(count%10==0){
System.out.println(" ");
}
}
}
System.out.println("共有素数:"+ count + "个");
scan.close();
}
public static boolean isPrime(int n){
boolean tag = true;
if(n==1){
tag = false;
}else{
for(int i=2;i<=Math.sqrt(n);i++){
if(n%i==0){
tag = false;
break;
}
}
}
return tag;
}
}
结果如下:
`“