📜  反转负数 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:37.153000             🧑  作者: Mango

代码示例1
Number -- Reverse negative number
Write a return method that can reverse negative number and return it as int
 
Solution:
public static int reverseNum(int  num) {
String str = new StringBuilder(""+num).reverse().toString();
if(num < 0) {
str = "-"+str.substring(0, str.length()-1);
}
return Integer.valueOf(str);
}