created
last reply
- 1
reply
- 771
views
- 2
users
- 1
like
- 2
links
Because you’re comparing objects, not their values, and num3 and num4 are different objects. (100 works as expected for num1 and num2 because of Java’s special treatment and caching of Integers between -128 and 127.)
Bottom line is you should be comparing using .equals for objects such as Integers, and reserve == and != for primitives.
Suggested Topics
Topic | Category | Replies | Views | Activity |
---|---|---|---|---|
Please Help with Time Limit exceeded in GERGOVIA -Wine trading in Gergovia | JAVA based languages | 4 | 157 | Jul '24 |
Help Regarding TLE in KQUERY | JAVA based languages | 1 | 131 | Jul '24 |