+ 1

Something weird

https://code.sololearn.com/cJaUUFw4Y5y7/?ref=app How does this code go into negatives??? Like what in the holy hot crispy Kentucky fried chicken frick? Tryin to make a Fibonacci code. https://code.sololearn.com/cJaUUFw4Y5y7/?ref=app

30th Oct 2019, 1:22 AM
HAYDEN DIMARCANTONIO
HAYDEN DIMARCANTONIO - avatar
6 Respostas
+ 2
By default a java int is signed which means the last bit is used to signal if the number should be positive or negative. you end up overflowing that bit causing numbers to become negative by accident
30th Oct 2019, 1:30 AM
JME
+ 2
No clue, you can look up the supported ranges for java data types in the documentation. long will give you a larger range but will still overflow eventually
30th Oct 2019, 1:40 AM
JME
0
yo thats kinda weird
30th Oct 2019, 1:31 AM
HAYDEN DIMARCANTONIO
HAYDEN DIMARCANTONIO - avatar
0
do they explain that in the java course?
30th Oct 2019, 1:31 AM
HAYDEN DIMARCANTONIO
HAYDEN DIMARCANTONIO - avatar
0
oh ok. thx man!
30th Oct 2019, 1:42 AM
HAYDEN DIMARCANTONIO
HAYDEN DIMARCANTONIO - avatar