如果确定为五位数,要用数组的话:
public static void chekc(String number) {
char[] numArr = number.toCharArray();
if (numArr[0] == numArr[4] && numArr[1] == numArr[3] && numArr[2] == numArr[1] +1) {
System.out.println(number + "是回文数");
}
}
这样也可以判断。
其他判断方法:
public static void chekc(String number) {
String num = String.valueOf(number);
String reversenum = new StringBuffer(num).reverse().toString();
if (reversenum.equalsIgnoreCase(num)) {
System.out.println(number + "是回文数");
} else {
System.out.println(number + "不是回文数");
}
}