In the calculation n / !2
You effectively do n / 0
.
!
is short for not
, not 2
is a boolean expression where 2
(anything but 0
) is true
.
not true
is false
.
false
is promoted to an int
in the calculation and false
there becomes 0
.
Solution: Use n % 2 != 0
or n & 1
to check for odd numbers.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…