C# 从键盘输入一个年份,判断该年是否为闰年(要求使用if语句的嵌套来实现).

如题所述

Console.Write("请输入一个年份:");
long x = Convert.ToInt64(Console.ReadLine());
if (x % 4 == 0)//当x可以被4整除时
{
if (x % 100 != 0)//当x不能被100整除时
{
Console.WriteLine("该年份为闰年");
}
else if (x % 400 == 0)//当x可以被400整除时
{
Console.WriteLine("该年份为闰年");
}
else//当x可以被100整除时
{
Console.WriteLine("该年份为非闰年");
}
}
else//当x不能被4整除时
{
Console.WriteLine("该年份为非闰年");
}
Console.ReadLine();
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-12-11
呵呵,3层if嵌套。
if(year%4 ==0){
if(year%100 == 0){
if(year%400==0){
return true;
}esle{
return false;
}
}else{
return true;
}
}else{
retur false;
}本回答被网友采纳
第2个回答  2012-12-11
if((year%4==0 && year%100!=0)|| year%400==0)
{
//闰年,do things
}
else
{
//非闰年,do things
}
第3个回答  2012-12-11
楼上的

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网