public int reverse(int x) {
            int result = 0;
            int cur = Math.abs(x);
            while (cur >= 10) {
                int tmp = cur % 10;
                result = result * 10 + tmp;
                cur = cur / 10;
            }
            result = result * 10 + cur;
            if (x < 0)
                return 0 - result;
            else
                return result;
        }