How do I end a program if I have multiple methods?

–1 vote
asked Aug 2 by Logan Wright (150 points)
If I wanted to make a system that took an answer, and based on that answer either continued the program or ended it, how would I do that?  More generally, how would I end a program at a certain point?

1 Answer

+1 vote
answered Aug 5 by Peter Minarik (7,160 points)

Use

System.exit(errorCode);

where errorCode indicates the return code of the program. Usually it's 0 for normal termination.

See the documentation: https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#exit(int)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...