DEV Community

Ildarov
Ildarov

Posted on

 

Java math 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 (5)

Collapse
 
awwsmm profile image
Andrew (he/him)

10106.0, I think. Because:

null != null == true
1 & 2 == 0
Collapse
 
devit951 profile image
Ildarov

No, you made a little mistake, null == null always true, therefore null != null should always be false.

Collapse
 
awwsmm profile image
Andrew (he/him)

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.

Thread Thread
 
devit951 profile image
Ildarov

Wow, thank you! I didn't know it.

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.