码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-09-11 20:35:01      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

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();
}
}
}

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

标签:

原文地址:http://www.cnblogs.com/skyay/p/4801866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!