System.exit()方法参数

说明文档:System (Java Platform SE 8 )

终止当前正在运行的Java虚拟机。该参数用作状态代码;按照惯例,非零状态码表示异常终止

此方法调用类Runtime中的exit方法。此方法从不正常返回。

调用System.exit(n)实际上等效于以下调用:

Runtime.getRuntime().exit(n)

参数:

status—退出状态。

语法:
       System.exit(参数);

状态:
        正常终止当前运行的JVM:System.exit(0)
        异常终止当前运行的JVM:System.exit(非零的int型参数)

System.exit(-1)使用

import java.util.Scanner;
public class SwitchStatement
{
    public static void main(String args[])
    {
        int intMonth;
        System.out.println("请输入一个月份:");
        Scanner scanner = new Scanner(System.in);
        intMonth = scanner.nextInt();
        if(intMonth<1 || intMonth>12)
        {
            System.out.println("输入错误:月份必须在1--12之间!");
            System.exit(-1);
        }

        switch(intMonth)
        {
            case 12:
            case 1:
            case 2:
                System.out.println(intMonth+"月是冬季");
                break;
            case 3:
            case 4:
            case 5:
                System.out.println(intMonth+"月是春季");
                break;
            case 6:
            case 7:
            case 8:
                System.out.println(intMonth+"月是夏季");
                break;
            case 9:
            case 10:
            case 11:
                System.out.println(intMonth+"月是秋季");
         }

     }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值