您的位置:首页 > 其它

计算输入的年份是否为闰年,并利用条件运算符输入“是”或者“不是”

2015-09-11 18:51 330 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: