Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTJ von Stein
1,188 PointsHow do I exit a program?
what command exits a java program?
int numberOfPeople = 3;
if (numberOfPeople<4) {
console.printf("Your table is ready!");
}
2 Answers
TJ von Stein
1,188 Points//Thanks Ryan // I was in a loop for the original question, and how I got the code to manually exit, is
System.exit(0);
Ryan Ruscett
23,309 PointsThe program exits when there is noting left to do. As an example, the program above. It will exit as soon as it prints. It changes a bit hen you have a GUI and hit the the x in the corner to close the window. That is a system exit. But yeah, a program closes when its finished running.
Ryan Ruscett
23,309 PointsRyan Ruscett
23,309 PointsIn a loop the program should exit when the loop is finished. If you want to end the loop based on some condition, you use the break keyword. Which will then exit the loop and run the rest of the code or exit the program. But yeah what you did can work too.