java - My program is not working properly -
i have following code in java overflows when shouldn't. why?
public classo { public static void main(string[] args) { int big = integer.max_value; system.out.println("big = " + big); long bigger = big + 2; system.out.println("bigger = " + bigger); } }
i output:
big = 2147483647 bigger = -2147483647
why overflow? have defined bigger long. wrong?
big+2
overflow big max. value while (long) big
not
long bigger = (long) big +2
will work treat big long instead of integer.
so make cast of float it.
Comments
Post a Comment