How does this work? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

How does this work?

int x,y; x = 60; y = x; System.out.print("xd"); System.exit(x); System.out.print(y);

26th Mar 2019, 8:33 AM
Purvesh Pawar
Purvesh Pawar - avatar
1 ответ
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
27th Mar 2019, 6:55 PM
Jenine