创建一个控制台应用程序,主要实现使用条件运算符?:判断用户输入的年份是否为闰年的功能,具体实现时,首先使用Console.Write输出提示文字“请输入年份:”,然后使用ushort对象的TryParse方法将Console.ReadLine输入转换为16位无符号整数,最后使用条件运算符判断?:判断转换后的16位无符号整数是否是闰年。判断条件如:(P_usint_temp % 4 == 0 && P_usint_temp % 100 != 0) || P_usint_temp % 400 == 0。
using System;
namespace _1_5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个年份:");
string year;
year = Console.ReadLine();
int year1= Convert.ToInt16(year);
// Console.WriteLine(year1);
string answer = (year1 % 4 == 0 && year1 % 100 != 0) || year1 % 400 == 0 ? "是闰年" : "不是闰年";
Console.WriteLine("{0}年{1}",year,answer);
Console.WriteLine();
}
}
}
效果: