+ 2
How are Fibonacci numbers becoming negative after some time ? Can anyone explain it?
Recently I saw Fibonacci numbers may be negative but I can't understand how they become negative . So explain it deeply that's why I can understand Thank you https://code.sololearn.com/cyD6Ol5V38el/?ref=app
5 Respuestas
+ 5
I'm thinking you are witnessing integer overflow phenomenon
https://blog.webnersolutions.com/java-int-and-float-overflow-and-underflow-with-examples/
+ 3
Jay Matthews Ipang Thank you so much
+ 3
use long instead int and
by Math.addExact(a,b) it produces Exception for overflow
then can catch the Exception by try - catch statements
sum = Math.addExact(sum, b);
long temp = b;
b = Math.addExact(a,b);
a = temp;
also for higher numbers there are class
java.math.BigInteger
+ 1
Jay Matthews
Overflow in java??
I thought that java doesn't need dynamically allocated memory.
Why java's int is not like other languages like JavaScript and Python ??
Java is not compiled. So it doesn't have to use int data type like compiles languages
Correct me if I'm wring
0
hi