如题所述
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();
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;
}本回答被网友采纳
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
}
{
//闰年,do things
}
else
{
//非闰年,do things
}
第3个回答 2012-12-11
楼上的