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 Class

public class ExitMethod {
    public static void main(String[] args) {
        // declaring an array
        int 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值