This is happens because the reversed number of 2147483642
is 2463847412
, and this number is greater then Intrgre.MAX_VALUE
which is 2147483647
, so the number became less than 0.
This is happens to 2147483623
too, because his reversed number is 3263847412
, and this number is greater then Intrgre.MAX_VALUE
.
To fix that, I see two possible solutions:
- Use
long
instead of int
.
- Rewrite the method to work with
String
, because you aren't really do any calculations (You can use string.charAt(int index)
to get the digits one bt one).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…