写一个方法,返回指定年月份最后一天到底是多少号?

public class Test2 {
    public boolean isLeapYear(int year) {
        if((year%4==0 && year%100!=0) || (year%400==0)){
            System.out.println("最后一天为28");
             return true;}
        else {System.out.println("最后一天为29");
             return false;} }
    public void day(int month){
        switch (month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            System.out.println("最后一天为31天");
            break;
        case 2:isLeapYear(2018);            //今年为1018年
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            System.out.println("最后一天为30天");
        default:
            System.out.println("不属于今年2018年");
            break;
        }
    }
public static void main(String[] args) {
    Test2 test2 = new Test2();
    test2.day(2);

}
}

猜你喜欢

转载自blog.csdn.net/weixin_42428664/article/details/81809577
今日推荐