首页 > 其他 > 详细

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

时间:2015-09-11 20:31:46      阅读:435      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!