```
class Solution {
public int reverse(int x) {
int r = 0;
int count = 1;
try {
int x1 = Math.abs(x);
while ( x1 > 0){
int a = x1%10;
if(count > 9){
if(r == 214748364 && a>7)
r=0;
if(r > 214748364 && a>0){
r=0;
break;
}
}
r = r * 10 + a;
x1 = x1/10;
count++;
}
if(x < 0)
r = -r;
// 2147483643
// 32bit int - 2147483648
} catch (Exception e){
r=0;
}
return r;
}
}
```