解题思路:
import java.util.Scanner; public class C1250 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int a = sc.nextInt(), b = sc.nextInt(); for(int n = a; n <= b; n++){ if(F(n)) System.out.println(n); } } sc.close(); } private static boolean F(int n){ //1. 判断是否为素数 for(int i = 2; i * i <= n; i++){ if(n % i == 0) return false; } //2. 判断是否为回文数 String str = String.valueOf(n); int len = str.length(); for(int i = 0; i <= len/2; i++){ if(str.charAt(i) != str.charAt(len-1-i)) return false; } //默认返回true return true; } }
注意事项:
参考代码:
0.0分
0 人评分
C语言训练-排序问题<2> (C++代码)浏览:880 |
C语言训练-求具有abcd=(ab+cd)2性质的四位数 (C语言代码)浏览:562 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:665 |
ASCII帮了大忙浏览:748 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:518 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:587 |
1113题解浏览:784 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:664 |
有关字符,字符串的输入输出函数说明浏览:478 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:667 |