+ 1

How to stop runnung java program

how can i stop a running java program for example if the age <16 stop the program what code should i use

17th Mar 2018, 12:08 PM
yousef mohamed
yousef mohamed - avatar
5 Answers
+ 2
System.exit(0); Put it anywhere you want the JVM to stop execution.
17th Mar 2018, 12:15 PM
apex137
apex137 - avatar
+ 2
Depends on what are you mean for "with message"... Its a console or GUI Application? Anyway show message and wait for user interaction (key pressed on console and ok/close/quit/etc pressed in a simple exit dialog if is a GUI APP) therefore close app
17th Mar 2018, 12:22 PM
KrOW
KrOW - avatar
+ 1
what if i want to stop the program with message...like (sorry u r too young) what to do??
17th Mar 2018, 12:17 PM
yousef mohamed
yousef mohamed - avatar
+ 1
if(condition){ System.out.println("to young); System.exit(0); }
17th Mar 2018, 12:50 PM
Jeremy
Jeremy - avatar
0
public class Program { public static void main(String[] args) { java.util.scaner scan = new java.util.scaner (Systen.in); System.out.println("enter your age: "); int age = scan.nextint; if (age < 16 ){ System.out.println("sorry u r too young"); } } }
18th Mar 2018, 10:40 AM
Shehab Ahmed
Shehab Ahmed - avatar