题解 | #回文数判断#
回文数判断
https://www.nowcoder.com/practice/b685d58f237c4214ada27161304a74a3
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); Main main = new Main(); int number = console.nextInt(); System.out.println(main.palindromeNumber(number)); } public Boolean palindromeNumber(int number) { //思路:通过循环将number反转,再进行比较 int pnum=0; int num=number; int count=0; while(num!=0) { int i=num%10; pnum=(pnum+i)*10; num/=10; count++; } pnum/=10;//注意最后依次对反转后的数要除以10 if(pnum==number) { return true; } else { return false; } } }