当时面试的时候,给出了一道题目,就是让整数进行翻转,比如给出整数123,然后翻转成321,下面是代码实现
<span style="font-size:18px;">public class Solution {
public intreverse(int x) {
long tmp = x; // 防止结果溢出
long result = 0;
while (tmp != 0) {
result = result *10 + tmp % 10;
tmp = tmp /10; }
// 溢出判断
if (result < Integer.MIN_VALUE || result > Integer.MAX_VALUE)
{
result =0; }
return (int) result;
}
}
</span>