Java code executed in comments

Quick, what’s the output of this code snippet?

int x = 32;
// this is a comment \u000a x++;
System.out.println(x);

Since you’re reading this, you probably figure it’s a trick question and the answer is not 32. And you’d be correct. The answer is 33.

The \u000a that probably caught your eye is a unicode newline character. So the editor doesn’t break the line, but the JDK does.

What to give it a try?

Submit

int x = 32; // this is a comment \u000a x++; System.out.println(x);
>

Not sure what other kind of fun you could have with this, but it’s good for contest problems.

Leave a Reply

Your email address will not be published. Required fields are marked *