+ 2
How does this work?
int x,y; x = 60; y = x; System.out.print("xd"); System.exit(x); System.out.print(y);
1 Answer
0
So it works by initially printing the string âxdâ
System.exit() with a non-zero parameter passed in then stops the currently running Java Virtual Machine stating something went wrong. (Zero passed as a parameter states behaviour is expected and Iâm happy to terminate the program. Ref https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exit(int) ) exit() takes an int argument so you are able to call exit(x), this just reflects youâre aborting the program in an unhappy state
System.out.print(y) is then not executed. If you take the exit() call out, your output is
xd60
Using println rather than print would give
xd
60