import java.util.Scanner; //一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。 public class Test25 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = 0 ; String s = "0"; System.out.println("请一个输入整数:"); while (true) { s = sc.nextLine(); try { num = Integer.parseInt(s); break; } catch (NumberFormatException e) { System.out.println("输入非法,请重新输入整数:"); } } StringBuffer sb = new StringBuffer(); sb.append(s); sb.reverse(); if(sb.toString().equals(s)){ System.out.println(num+"回文数"); }else{ System.out.println(num+"不回文数"); } } }