您的位置:首页 > 编程语言 > C#

c#基础加强版之方法控制流复习-1关于方法的讲解

2013-11-19 22:35 351 查看
题一:我的code

namespace 老师的代码_练习题2
{
///实现输入年份,月份,输出该月的天数学;
class Program
{
static int ReadInt(string str)
{
return ReadInt(str,int.MinValue,int.MaxValue);
}

static int ReadInt(string str, int max)
{
return ReadInt(str,int.MinValue, max);
}
static int ReadInt(string str, int min,int max)
{
int inputNumber;
do
{
Console.WriteLine(str);
try
{
inputNumber = Convert.ToInt32(Console.ReadLine());
if (inputNumber>min && inputNumber<max)
{
break;
}
else
{
Console.Write("您的输入有误,");
}
}
catch
{
Console.Write("您的输入有误,");
}

} while (true);
return inputNumber;
}

static int GetDays(int year,int month)
{
if (month==2)
{
if (year%400==0 && year%100!=0 || year%4==0)
{
return 29;
}
return 28;
}
else
{
switch (month)
{
case 2 :
case 4:
case 6:
case 9:
case 11:
return 30;
default:
return 31;
}
}
}

static void Main(string[] args)
{
int year = ReadInt("请输入年份", 2012);
int month = ReadInt("请输入月份", 0, 13);
Console.WriteLine(GetDays(year, month));
Console.ReadKey();
}
}
}


View Code

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐