判断每个月有多少天

import java.util.Scanner;

/*
 * 
 * 
 * 
 */
public class Demo {
    public static void main(String[] args) {
     //提示用户输出年数个月份
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入月数和年数");
        int mouth = sc.nextInt();
        int year =sc.nextInt();
        //判断天数
        for(;;){
        if(mouth>0&&mouth<13){
        switch(mouth){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            System.out.println(year+"年"+mouth+"月"+"有31");
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            System.out.println(year+"年"+mouth+"月"+"有30天");
            break;
        case 2:
            if(year%4==0){
                System.out.println(year+"年"+mouth+"月"+"有29天");
            }else{
                System.out.println(year+"年"+mouth+"月"+"有28天");
            }
            break;
        //default:
            //System.out.println("你输入的月份有误!请重新输入");
            
            }
        //跳出循环
        break;
        }else{
            System.out.println("你输入的月份有误,请重新输入月份");
            mouth =sc.nextInt();
        }
    }
    }
}

 

posted @ 2017-04-01 20:28  皮皮虾我们上  阅读(974)  评论(0编辑  收藏  举报