xxxxxxxxxx
public class SampleExitMethod {
public static void exampleMethod(int[] array1) {
for (int i = 0; i < array1.length; i++) {
//Check condition for i
if (i > 4) {
System.out.println("Terminating JVM...");
//Terminates JVM when if condition is satisfied
System.exit(0);
}
System.out.println("Array Index: " + i + " Array Element: " + array1[i]);
}
}
public static void main(String[] args) {
int[] array1 = { 0, 2, 4, 6, 8, 10, 12, 14, 16 };
//function call
exampleMethod(array1);
}
}