public static String intToString(int x) {
        boolean is_negative = false;
        if (x < 0) {
            x = -x;
            is_negative = true;
        }

        StringBuilder s = new StringBuilder();
        while (x != 0) {
            s.append((char)('0' + x % 10));
            x /= 10;
        }
        if (s.length() == 0) {
            return "0";  // x is 0.
        }

        if (is_negative) {
            s.append('-');
        }
        s.reverse();
        return s.toString();
    }