public static void main(String[] args) {
//start 开始的数
//end 结束的数
int count = 0, start, end;
Scanner scanner = new Scanner(System.in);
String result = scanner.nextLine();
String[] s = result.split(" ");
start = Integer.valueOf(s[0]);
end = Integer.valueOf(s[1]);
int i, j;
//判断是否为素数
for (i = start; i <= end; i++) {
for (j = 2; j < i; j++) {
if (i % j == 0) {
break;
}
}
if (i == j) {
System.out.print(i + " ");
++count;
//判断每一行第十个换行
if (count == 9) {
System.out.println(i);
count = 0;
}
}
}
}
package test;
import java.util.Scanner;
public class SuShu {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int M = 0,N = 0;
boolean flag = true;
while(flag){
System.out.println("请输入两个整数:");
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
M = Integer.parseInt(input.trim().split(" ")[0]);
N = Integer.parseInt(input.trim().split(" ")[1]);
if(M >N) {
System.out.println("M不能大于N!"); continue;
}
if(N > 10000) {
System.out.println("N不能大于10000"); continue;
}
flag = false;
}
int k = 0,l = 1;
for(int i =0; i <= 10000; i++){
if(isPrimeNumber(i)){
k++;
if(k>=M && k<=N){
if(l==10){
l++;
System.out.print(i);
System.out.println();
l = 1;
}
else {
System.out.print(i+" ");l++;
}
}
if(k > N) break;
}
}
}
public static boolean isPrimeNumber(int a){
int i =2;
while(i if(a%i==0) break;
i++;
}
if(i==a) return true;
else return false;
}
}