+ 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
5 Antworten
+ 2
System.exit(0);
Put it anywhere you want the JVM to stop execution.
+ 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
+ 1
what if i want to stop the program with message...like (sorry u r too young) what to do??
+ 1
if(condition){
System.out.println("to young);
System.exit(0);
}
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");
}
}
}