class Solution {
public int reverse(int x) {
boolean flag = false;
try{
if(x == 0){
return 0;
}else{
if(x < 0){
x = Math.abs(x);
flag = true;
}
String str = x + "";
String result = "";
for(int i = str.length()-1; i>=0; i--){
result += str.charAt(i) + "";
}
if(flag){
return -Integer.parseInt(result);
}else{
return Integer.parseInt(result);
}
}
}catch(Exception e) {
return 0;
}
}
}