如果确定为五位数,要用数组的话:
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 + "不是回文数");
}
}
import java.util.*;
class 回文
{
public static void main(String[] args)
{
Scanner a=new Scanner(System.in);
System.out.println("请输入一个五位数:");
int b=a.nextInt();
if(b/10000==b%10&&b/1000%10==b/10%10)
{
System.out.println("该数是回文数");
}
else
{
System.out.println("该数不是回文数");
}
}
}