Why does this code, written backwards, print “Hello World!”

Here is some code that I found on the Internet:

class M‮{public static void main(String[]a‭){System.out.print(new char[]
{'H','e','l','l','o',' ','W','o','r','l','d','!'});}}    

This code prints Hello World! onto the screen; you can see it run here. I can clearly see public static void main written, but it is backwards. How does this code work? How does this even compile?

Edit: I tried this code in IntellIJ, and it works fine. However, for some reason it doesn’t work in notepad++, along with cmd. I still haven’t found a solution to that, so if anyone does, comment down below.

5 Answers
5

Leave a Comment