回文数是指正序和倒序一样的数,例如:12321
编写这个程序可以使用while循环,将这个数反过来然后和原来的数进行对比。
package firstDemo;
import java.util.Scanner;
public class Test1{
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
int x=scanner.nextInt();
int temp=x;
int num=0;
while(x!=0) {
int ge=x%10;
x=x/10;
num=num*10+ge;
}
System.out.println(num==temp);
}
}