**Java**

```
class Solution {
String xy="";
public int reverse(int x) {
try
{
if(x==0)
{
return (0);
}
if(x<0)
{
x=Math.abs(x);
xy="-";
}
while(x!=0)
{
xy=xy+(x%10);
x=x/10;
}
return (Integer.parseInt(xy));
}catch(Exception e)
{
return 0;
}
}
}
```