回文素数

【题目描述】
回文素数是指,如果一个正整数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;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值