Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java multiplication of negative numbers

In normal maths terms, -1756046391 * -1291488517 will equal 2267913749295792147.

When i enter the exact same equation in java, i get the answer: -1756046391 * -1291488517 = 19.

Can anyone shed any light on this?

like image 819
Adam Avatar asked Aug 15 '26 09:08

Adam


1 Answers

Overflow.

Check out Integer.MAX_VALUE. An Integer in Java is a 32 bit 2s complement value. You can't exceed the MAX_VALUE.

like image 176
duffymo Avatar answered Aug 16 '26 22:08

duffymo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!