标题:为什么我输入2月的时候总是不显示天数,求大神解答!!!
只看楼主
a4709
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-3-21
结帖率:0
已结贴  问题点数:20 回复次数:3 
为什么我输入2月的时候总是不显示天数,求大神解答!!!
int  year,month;
            string a="";
            
            Console.WriteLine("请输入年份和月份");
            year = Convert.ToInt32(Console.ReadLine());
            month = Convert.ToInt32(Console.ReadLine());
            if (month <= 12 && month >= 1)            
                switch (month)
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12: a = "31"; break;
                    case 4:
                    case 6:
                    case 9:
                    case 11: a = "30"; break;
                }               
                Console.WriteLine("{0}年{1}月有{2}天", year, month, a);
            if (month >12||month <1)               
                Console.WriteLine("非法数据");
                Console.ReadLine();                 
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
            {
                switch (month)
                {
                    case 2: a = "29"; break;
                }
                        Console.WriteLine("{0}年{1}月有{2}天", year, month, a);
               
               
                                   
                       Console.ReadLine();
            }
2014-03-26 17:59
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:7 
逻辑挺乱

DO IT YOURSELF !
2014-03-26 18:49
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2545
专家分:9359
注 册:2007-11-3
得分:7 
程序代码:
 switch (month)
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12: a = "31"; break;
                    case 4:
                    case 6:
                    case 9:
                    case 11: a = "30"; break;
                }               
这里面没有2 显示什么啊

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2014-03-27 10:58
步向巅峰
Rank: 5Rank: 5
来 自:河南
等 级:贵宾
威 望:17
帖 子:110
专家分:371
注 册:2013-4-26
得分:7 
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
            {
                switch (month)
                {
                    case 2: a = "29"; break;
                }
                        Console.WriteLine("{0}年{1}月有{2}天", year, month, a);
               
               
                                   
                       Console.ReadLine();
            }
你在上面的switch中没有case 2
在这段代码中定义的也是在闰年的时候输出二月的天数,那么如果你输入的年份不是闰年的话没有办法输出
2014-03-28 13:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-429203-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.319707 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved