c#判断输入的值是平年还是闰年,并输出

///
/// 主方法调用两个判断方法
///
///

   static void Main(string[] args)
    {
        Console.WriteLine("请输入你想输入的年份!");
        string year = Console.ReadLine();
        string Return = JudgeYear(year);
         Console.WriteLine(Return);
        if (Return == "请输入正确格式的年份!")
        {
            return;
        }
        string hint = Hint(year);
        Console.WriteLine("这是一个{0}年",hint);
    }

///
/// 判断输入的值格式是否正确
///
///
///

    static string JudgeYear(string  year) 
    {
        string hint = "格式正确!";
        try
        {
           int value = Convert.ToInt32(year);      
            
        }
        catch (Exception)
        {
            hint =  "请输入正确格式的年份!";
        }
        return hint;
    }

///
/// 判断输入的年份是闰年还是平年
///
///
///

    static string Hint(string year) 
    {
        int years = Convert.ToInt32(year);
        string hint = "平";
        if (years % 400 == 0 || (years % 4 == 0 && years % 100 == 0))
        {
            hint = "闰";
        }
        return hint;
    }

你可能感兴趣的:(c#,开发语言)