reverse negative number

Solutions on MaxInterview for reverse negative number by the best coders in the world

showing results for - "reverse negative number"
Oriane
16 Aug 2018
1Number -- Reverse negative number
2Write a return method that can reverse negative number and return it as int
3 
4Solution:
5public static int reverseNum(int  num) {
6String str = new StringBuilder(""+num).reverse().toString();
7if(num < 0) {
8str = "-"+str.substring(0, str.length()-1);
9}
10return Integer.valueOf(str);
11}