0
int overrun issue
Hello I have a question. int has a range from -2 to the power of 32 to 2 to the power of 32 -1. If I now assign a int variable to 3 * 1 * 10 to the power of 9, System.out.println will give me an overrun. Now the Question is . What number do i get? does it end with 5 or 6? With the IDE i get a 6 but when i count it with Geogebra i get 5. thanks for your help
5 Answers
0
Sanoj i don't get what do you mean by 5 or 6..?
Integer range in java is -2147483648 to 2147483647.
If you exceed the value of max value then you will get the number count from minimum value..
Add an example for your description...
0
Int has a range -2 in power of 31 to 2 in power of 31 - 1, btw. 2 in power of 32 is a total number of values.
0
@ Jayakrishna
with 5 or 6 i mean the last digit of the result when you calculate
3*1 *10^9. What result do you get?
-1294967295 or -1294967296
0
6 in code playground
https://code.sololearn.com/cHIrcLyoyF6I/?ref=app
0
With 3*10^8 only you get correct result, and 3*10^9 you are getting overrun..
6 getting but 5 or 6 both overrun values.. What is the difference..