1.Can system.exit() be used at sentinel value?
Why would you want to use it as sentinel values? You probably can't use it as a loop guard in your loop, because once exited, your program terminates.
Secondly, if there is any unfinished task, your program will terminate abruptly.
If not what purpose would 2.system.exit() provide?
You may look at this post regarding Java's System.exit(): Java's System.exit(0); vs C++ return 0;
3.if this code is in a loop and they enter 1. Would it exit?
Your code will exit eventually no matter what is being entered. It will not only exit the loop, it will terminate your program. To jump out of a loop, you use break
and not System.exit()
.
To skip the rest of code in a loop, you use continue
.