C#入门 闰年问题 看看哪出错了

来源:百度知道 编辑:UC知道 时间:2024/06/22 01:15:24
我输入小于2202的数就会从2202开始:2202不是闰年 2203不是闰年........2500不是闰年
怎么回事 请教高手
囧 忘了复制代码..
using System;
using System.Collections.Generic;
using System.Text;

//判断是否是闰年
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int year;int y;
Console.Write("请您输入年数字:");
year = Convert.ToInt32(Console.ReadLine());
for (y = year; y <= 2500; y++)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
Console.WriteLine("您输入的{0}年是闰年!", y);
}

} Console.ReadLine();
}
}
}

我刚刚试了下 发现只要输入一个闰年 就会出现2002年不是闰年 2003年不是闰年...2500不是闰年
输入一个不是闰年的就是什么都没有

Console.WriteLine("您输入的{0}年是闰年!", y); Console.WriteLine("您输入的{0}年不是闰年!", y);

这个不能放到for循环里面
for (y = year; y <= 2500; y++)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
Console.WriteLine("您输入的{0}年是闰年!", y); return;
}
else
{
Console.WriteLine("您输入的{0}年不是闰年!", y); return;

}

至少也要把代码发出来啊。
总不能 让我们猜吧?

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace Temp
{
class Program
{
static void Main(string[] args)
{
int year;
Console.Write("请您输入年数字:");
year = Convert.ToInt32(Console.ReadLine());
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
Console.WriteLine("您输入的{0}年是闰年