Reverse Integer
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class Solution { 2 public int reverse(int x) { 3 int sign = 1; 4 if(x<0) 5 sign=-1; 6 int res = 0; 7 x= Math.abs(x); 8 while(x>0){ 9 res = 10*res+x%10; 10 x /=10; 11 } 12 if(res<0) return -1; 13 return res*sign; 14 } 15 }