使用System.exit(0) [英] Use of System.exit(0)

查看:118
本文介绍了使用System.exit(0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class WrapperTest {
    static {
        print(10);
    }

    static void print(int x) {
        System.out.println(x);
        System.exit(0);
    }
}

在上面的代码中系统.exit(0)用于停止程序。该方法采用什么参数?为什么我们将它作为 0 给出。任何人都可以解释这个概念吗?

In the above code System.exit(0) is used to stop the program. What argument does that method take? Why do we gave it as 0. Can anyone explain the concept?

推荐答案

来自 JAVA文档


该参数用作状态代码;按惯例
,非零状态代码
表示异常终止。

The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

并且维基百科添加了更多信息。

这篇关于使用System.exit(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆