集册 Java实例教程 掉落开关

掉落开关

欢马劈雪     最近更新时间:2020-01-02 10:19:05

656
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
掉落开关

class SwitchDemo2 {

    public static void main(String[] args) {/* 来自 N o w J a v a . c o m - 时  代  Java*/


        int month = 2;

        int year = 2000;

        int numDays = 0;


        switch (month) {

        case 1:

        case 3:

        case 5:

        case 7:

        case 8:

        case 10:

        case 12:

            numDays = 31;

            break;

        case 4:

        case 6:

        case 9:

        case 11:
        /** 
         来自 n o w j a   v  a . c o m - 时  代  Java**/

            numDays = 30;

            break;

        case 2:

            if (((year % 4 == 0) && !(year % 100 == 0))

                    || (year % 400 == 0))

                numDays = 29;

            else

                numDays = 28;

            break;

        default:

            System.out.println("Invalid month.");

            break;

        }

        System.out.println("Number of Days = " + numDays);

    }

}


展开阅读全文