java笔试题:随机生成一个4位数字的年号,判断是否是闰年?

老规矩,直接上代码:

    /**
     * 随机生成一个4位数的年号,判断概念是否为闰年并输出相应的信息。
     */
    public static void LeapYear(){
        int year = (int)(Math.random() * 10000);
        boolean exp1 = year % 400 ==0;
        boolean exp2 = (year %4 == 0 )&&(year % 100 != 0);
        String string = (exp1 || exp2)?"是闰年":"不是闰年";
        System.out.println(year + " " + string);
    }

结果如下:

原文地址:https://www.cnblogs.com/superdrew/p/9736674.html