System.exit() method exit current program by terminating running Java virtual machine.
0 -> Successful terminate
Non Zero -> Genarally indicate unsuccessful terminate
0 -> Successful terminate
Non Zero -> Genarally indicate unsuccessful terminate
// A Java program to demonstrate working of exit() import java.util.*; import java.lang.*; class GfG { public static void main(String[] args) { int arr[] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 }; for ( int i = 0 ; i < arr.length; i++) { if (arr[i] >= 5 ) { System.out.println( "exit..." ); // Terminate JVM System.exit( 0 ); } else System.out.println( "arr[" +i+ "] = " + arr[i]); } System.out.println( "End of Program" ); } } |
No comments:
Post a Comment