```
public class Solution {
public int reverse(int x) {
String number = "" + x;
String sign = "";
String result = "";
try
{
if(x == 0)
{
return x;
}
else if(x < 0)
{
sign = "" + number.charAt(0);
number = number.substring(1);
}
for(int i = number.length()-1; i >= 0; i--)
{
result += number.charAt(i);
}
return Integer.parseInt(sign + result);
}
catch(NumberFormatException e)
{
return 0;
}
}
```

}