输入一个带符号的整数,得到它的相反数:
例1:
输入: 123 输出: 321
例2:
输入: -123 输出: -321
例3:
输入: 120 输出: 21
public int reserve(int x){
int result = 0;
while(x!=0){
int tail = x % 10;
int newResult = result * 10 + tail;
if((newResult-tail)/10 != result){
return 0;
}
result = newResult;
x = x / 10;
}
return result;
}