本帖最后由 wwwconsumer 于 2014-7-6 05:36 编辑
我是初学者,正在学习C#入门,非科班出身,可以开贴吗?先贴一个学习switich语句的笔记:
任意输入一个年月日,程序自动计算剩余天数
[C#] 纯文本查看 复制代码 Console.WriteLine("请输入年月日");
int y = Convert.ToInt32(Console.ReadLine());
int m = Convert.ToInt32(Console.ReadLine ());
int d = Convert.ToInt32 (Console.ReadLine ());
int total =365;
if((y%4==0&& y%100!=0)||y%400==0)
total = 366;
switch (m)
{
case 1:total-=31;goto case 2;
case 2:
if((y%4==0&& y%100!=0)||y %400==0)
total -=29;
else
total -=28;
goto case 3;
case 3:total -=31;goto case 4;
case 4:total -=30;goto case 5;
case 5:total -=31;goto case 6;
case 6:total -=30;goto case 7;
case 7:total -=31;goto case 8;
case 8:total -=31;goto case 9;
case 9:total -=30;goto case 10;
case 10:total -=31;goto case 11;
case 11:total -=30;goto case 12;
case 12:total -=31;goto default;
default :total +=d;break ;
}
Console.WriteLine ("{0}月{1}日是{2}年的第{3}天。",m,d,y,total); |