博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConditionOperator
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入一个年份:");//屏幕输入提示字符串
string strYear = Console.ReadLine();//获取用户输入的年份
int intYear = Int32.Parse(strYear);//将输入的年份转换成int类型
//计算输入的年份是否为闰年,并利用条件运算符输入“是”或者“不是”
string strYesOrNo = ((intYear % 400) == 0) || (((intYear % 4) == 0) && ((intYear % 100) != 0)) ? "是" : "不是";
Console.WriteLine("{0}年{1}闰年", strYear, strYesOrNo); //输出结果
Console.ReadLine();
}
}
}