Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

reverse negative number

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);
}
 
PREVIOUS NEXT
Tagged: #reverse #negative #number
ADD COMMENT
Topic
Name
9+7 =