We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I would just like to add in Java - the compiler treats all nontype numerals as int first.
So 3 + 1 <==== is treated as int first and foremost.
long result = 3 + 1 <--- is int THEN is converted to long after the sum is calculated.
long result = Integer.MAX_VALUE + 1; //will produce: -2147483648
Thanks for the tip. I couldn't figure out why changing the input type from int to long changed my output! Now everything works. Thanks!
EDIT: BTW This isn't a bug. I took the Java certification class, and this is part of the compiler knowledge needed to pass the test. I just forgot about it :(
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #6: Sum square difference
You are viewing a single comment's thread. Return to all comments →
I would just like to add in Java - the compiler treats all nontype numerals as int first.
So 3 + 1 <==== is treated as int first and foremost.
long result = 3 + 1 <--- is int THEN is converted to long after the sum is calculated.
long result = Integer.MAX_VALUE + 1; //will produce: -2147483648
Thanks for the tip. I couldn't figure out why changing the input type from int to long changed my output! Now everything works. Thanks!
EDIT: BTW This isn't a bug. I took the Java certification class, and this is part of the compiler knowledge needed to pass the test. I just forgot about it :(