public class Solution {
    /**
     * 
     * @param x int整型 
     * @return int整型
     */
    public int reverse (int x) {
        // write code here
        if(x == 0){
            return 0;
        }
        boolean f = false;
        if(x < 0){
            f = true;
            x = -x;
        }
        String value = String.valueOf(x);
        char[] data = value.toCharArray();
        StringBuilder sb = new StringBuilder();
        for(int j = data.length - 1;j>= 0;j--){
            sb.append(data[j]);
        }
        String finalData = sb.toString();
        long temp = Long.parseLong(finalData);
        if(f){
            temp = -1 *temp;
        }
        if( -2147483648 < temp && temp <2147483647  ){
            return (int)temp;
        }
        return 0;
    }
}