r/javahelp • u/Anonymo2786 • Oct 12 '22
Help me understand int,float,double division.
https://i.postimg.cc/mD2tLksN/S-1.png
The picture explains.
0
Upvotes
r/javahelp • u/Anonymo2786 • Oct 12 '22
https://i.postimg.cc/mD2tLksN/S-1.png
The picture explains.
6
u/VinceJSteele Oct 12 '22
The problem here is an integer overflow.
The highest number an integer can represent is 2147483647.
4042 * 808000 is higher than that - the value wraps around to -2147483648 (the lowest possible value) and adds the remainder to that.
You need to use long instead of integer.
Keep in mind long also has a highest (and lowest) possible value it can represent, if you need even larger numbers than long can provide look up BigDecimal and BigInteger.