Java System类exit()方法及示例
系統類exit()方法 (System class exit() method)
exit() method is available in java.lang package.
exit()方法在java.lang包中可用。
exit() method is used to exit the currently running JVM (Java Virtual Machine).
exit()方法用于退出當前正在運行的JVM(Java虛擬機)。
exit() method is a static method, it is accessible with the class name too.
exit()方法是靜態方法,也可以使用類名進行訪問。
exit() method may be thrown various type of exception and the description of exception are given below,
exit()方法可能會引發各種類型的異常,下面給出了異常的描述,
SecurityException: If a particular method checkExit() does not allow exit with the given exit_status when security manager exists in the method.
SecurityException :如果特定方法checkExit()不允許在方法中存在安全管理器時使用給定的exit_status退出。
Syntax:
句法:
public static void exit (int exit_status);Parameter(s):
參數:
exit_status – represents the stages or level of termination of JVM, and here, the non-zero value represents the abnormal termination of JVM.
exit_status –表示JVM終止的階段或級別,此處,非零值表示JVM的異常終止。
Return value:
返回值:
The return type of this method is void, it does not return any value.
此方法的返回類型為void ,它不返回任何值。
Example:
例:
// Java program to demonstrate the example of // exit() method of System Classpublic class ExitMethod {public static void main(String[] args) {// declaring an arrayint array[] = {10,20,30,40,50};for (int i = 0; i < array.length; ++i) {if (array[i] < 60) {System.out.println("Element at index" + " " + i + " is " + array[i]);} else {System.out.println("We are exiting JVM normally");System.exit(0);}}} }Output
輸出量
E:\Programs>javac ExitMethod.java E:\Programs>java ExitMethod Element at index 0 is 10 Element at index 1 is 20 Element at index 2 is 30 Element at index 3 is 40 Element at index 4 is 50翻譯自: https://www.includehelp.com/java/system-class-exit-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java System类exit()方法及示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国窖多少钱一瓶啊?
- 下一篇: nextshort_Java扫描仪的ne