【题目描述】
回文素数是指,如果一个正整数n从左向右和从右向左读结果都相同且是素数,则称之为回文素数。编程找出1000以内的回文素数
【输入描述】
无输入
【输出描述】
输出有若干行,每行输出5个回文素数。
【输入样例】
【输出样例】
2 3 5 7 11
101 131 151 181 191
313 353 373 383 727
757 787 797 919 929
public class huiwenShu {
/**
* @param args
*/
public static void main(String[] args) {
int count=1;
for(int i=1;i<1000;i++){
if(isSushu(i)==true&&isHuiwen(i)==true){
System.out.print(i+" ");
count++;
if(count%5==0){
System.out.println();
}
}
}
}
private static boolean isHuiwen(int n) {
boolean flag=false;
for(int i=2;i<Math.sqrt(n);i++){
if(n%i==0){
break;
}
else{
flag=true;
}
}
return flag;
}
private static boolean isSushu(int n) {
String str=trans(n);
int ls=str.length();
for(int i=0;i<ls;i++){
if(str.codePointAt(i)!=str.codePointAt(ls-1-i)){
return false;
}
}
return true;
}
private static String trans(int bk) {
int a=bk;
String res="";
while(a!=0){
int b=a%10;
res=b+res;
a=a/10;
}
return res;
}
}