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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -