m0_61890470 2021-10-24 10:22 采纳率: 100%
浏览 36
已结题

switch语句编写daysOfMonth方法(形参名称为month),返回每个月的天数)

img

  • 写回答

2条回答 默认 最新

  • 梦屿千寻ོ꧔ꦿ  2021-10-24 11:44
    关注

    public class Test {

    public static void main(String[] args) {
        int month = 5;
        int day = daysOfMonth(month);
        System.out.println(month+"月是:"+day+"天");
    }
    
    public static int daysOfMonth(int month) {
        switch (month) {
        case 2:
            return 28;
            
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            return 31;
        case 4:
        case 6:
        case 9:
        case 11:
            return 30;
    
        }
        return 0;
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月18日
  • 已采纳回答 11月10日
  • 创建了问题 10月24日