资源限制
时间限制:1.0s 内存限制:256.0MB
一个数如果从左往右读和从右往左读数字是完全相同的,则称这个数为回文数,比如898,1221,15651都是回文数。编写一个程序,输入两个整数min和max,然后对于min~max之间的每一个整数(包括min和max),如果它既是一个回文数又是一个质数,那么就把它打印出来。要求,回文数和质数的判断都必要要用函数的形式来实现。
输入:
5 100
输出:
5 7 11
`
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int min = sc.nextInt();
int max = sc.nextInt();
//判断质数
for (int i = min; i <= max; i++) {
if (i > 1) {
boolean bool = true;
for (int j = 2; j <= Math.sqrt(i); j++)
if (i % j == 0) {
bool = false;
break;
}
if (bool) {
//判断回文数
String a = String.valueOf(i);
char[] c = a.toCharArray();
int front = 0;
int after = a.length() - 1;
while (front < after) {
if (c[front] != c[after]) {
bool = false;
break;
}
front++;
after--;
}
}
if (bool) System.out.print(i + " ");
}
}
}
}



