Answers for "how to flip a negative number to positive"

0

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);
}
Posted by: Guest on September-29-2021

Code answers related to "how to flip a negative number to positive"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language