Java中取余数: (结果与被除数同号)
1、 5 % 3 = 2;
2、 -5 % 3 = -2;
3、 5 % -3 = 2;
4、 -5 % -3 = -2;
public class Solution {
public int reverse(int x) {
int reverse = 0;
while (x != 0) {
if (reverse != 0 && Integer.MAX_VALUE / reverse < 10 && Integer.MAX_VALUE / reverse > -10) {
return 0;
}
reverse = reverse * 10 + x % 10;
x = x / 10;
}
return reverse;
}
}