Ildarov Posted on Apr 11, 2019 • Edited on Apr 11, 2019 Java math challenge #java #challenge What should be printed? int result = 0; result = result + (null != null ? 3 : 2); result += (1 & 2) == 1 ? 2 : 3; result += 1e5; result += 1e2; System.out.println(result); Enter fullscreen mode Exit fullscreen mode Top comments (4) Subscribe Submit Preview Dismiss Collapse Expand Andrew (he/him) Andrew (he/him) Andrew (he/him) Follow Got a Ph.D. looking for dark matter, but not finding any. Now I code full-time. Je parle un peu français. Email aww@awwsmm.com Location Ottawa, Canada Education Ph.D. in [Astroparticle] Physics Pronouns he / him Work Principal Consultant at Improving Joined Sep 15, 2018 • Apr 11 '19 Dropdown menu Copy link Hide 10106.0, I think. Because: null != null == true 1 & 2 == 0 Collapse Expand Ildarov Ildarov Ildarov Follow I am an Android developer. I like reading books about kotlin or java. In free time, I contribute to my own pet projects. Also like math. Work Android Developer Joined Mar 14, 2019 • Apr 11 '19 Dropdown menu Copy link Hide No, you made a little mistake, null == null always true, therefore null != null should always be false. Collapse Expand Andrew (he/him) Andrew (he/him) Andrew (he/him) Follow Got a Ph.D. looking for dark matter, but not finding any. Now I code full-time. Je parle un peu français. Email aww@awwsmm.com Location Ottawa, Canada Education Ph.D. in [Astroparticle] Physics Pronouns he / him Work Principal Consultant at Improving Joined Sep 15, 2018 • Apr 11 '19 Dropdown menu Copy link Hide Ah! You're right. 100105, then. (I also mistakenly added a .0 and lost a power of 10.) By the way, if you put java after the backticks on your code box, it applies Java syntax highlighting! This: will produce System.out.println(1 + 2 == 3); ...while this: will produce System.out.println(1 + 2 == 3); This works with JavaScript (js), Python (python), and lots of other languages, as well. Ildarov Ildarov Ildarov Follow I am an Android developer. I like reading books about kotlin or java. In free time, I contribute to my own pet projects. Also like math. Work Android Developer Joined Mar 14, 2019 • Apr 11 '19 Dropdown menu Copy link Hide Wow, thank you! I didn't know it. Some comments may only be visible to logged-in visitors. Sign in to view all comments. Code of Conduct • Report abuse
Top comments (4)
10106.0, I think. Because:No, you made a little mistake,
null == nullalways true, thereforenull != nullshould always be false.Ah! You're right.
100105, then. (I also mistakenly added a.0and lost a power of 10.)By the way, if you put
javaafter the backticks on your code box, it applies Java syntax highlighting!This:
will produce
...while this:
will produce
This works with JavaScript (
js), Python (python), and lots of other languages, as well.Wow, thank you! I didn't know it.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.