classSolution{ publicintreverse(int num){ //记录结果 long result = 0; while (num != 0) { result = result * 10 + sum % 10; sum /= 10; } return (int) result == result ? result : 0; } }
回文数
判断一个数是不是回文数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
classSolution{ publicbooleanisNum(int num){ //非负整数判断 if (num < 0) returnfalse; int temp = num; int result = 0; while (temp != 0) { result = result * 10 + temp % 10; temp /= 10; } return result == num; } }