privatestaticintreverseInteger(int num){ int res = 0; StringBuilder s = new StringBuilder(); // 处理小于0的情况 if(num < 0){ s.append("-"); num = -num; } while (num != 0){ s.append(num % 10); num /=10; } res = Integer.valueOf(s.toString()); return res; }
publicstaticvoidmain(String[] args){ int num = -1234; System.out.println(reverseInteger(num)); // -4321 }