Exit Notes:-
o defined in Sytem package
o Terminates the program with specific exit code
o Syntax : System.exit(exit_code)
where exit_code = 0 means the program finished normally
Any other value means error
Status - exit(0) - indicates Successful termination
Status - exit(-1) - indicates unsuccessful termination with Exception
Status - exit(1) - indicates Unsuccessful termination
public class SystemExitExample2 {
public static void main(String[] args) {
System.out.println("program will terminate when i is 1");
for(int i=10;i>0;i--) {
System.out.println("your no is "+i);
if(i==1){
System.out.println("Value is 1 now terminating your
program");
System.exit(1); //exit program
}
}
}
}
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
OUTPUT
program will terminate when i is 1
your no is 10
your no is 9
your no is 8
your no is 7
your no is 6
your no is 5
your no is 4
your no is 3
your no is 2
your no is 1
Value is 1 now terminating your program
o defined in Sytem package
o Terminates the program with specific exit code
o Syntax : System.exit(exit_code)
where exit_code = 0 means the program finished normally
Any other value means error
Status - exit(0) - indicates Successful termination
Status - exit(-1) - indicates unsuccessful termination with Exception
Status - exit(1) - indicates Unsuccessful termination
public class SystemExitExample2 {
public static void main(String[] args) {
System.out.println("program will terminate when i is 1");
for(int i=10;i>0;i--) {
System.out.println("your no is "+i);
if(i==1){
System.out.println("Value is 1 now terminating your
program");
System.exit(1); //exit program
}
}
}
}
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
OUTPUT
program will terminate when i is 1
your no is 10
your no is 9
your no is 8
your no is 7
your no is 6
your no is 5
your no is 4
your no is 3
your no is 2
your no is 1
Value is 1 now terminating your program