using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 小测试1
{
class Program
{
static void Main(string[] args)
{
//输入一个人的年龄,判断是否为青年。(18~40岁)
int age = Convert.ToInt32(Console.ReadLine());
bool isYoung = (age > 17) && (age < 41);
// 等同于bool isYoung = (age >= 18) && (age <= 40);
// 优点:少进行了两次 = 判断,更快速,更简洁。 缺点:牺牲了可读性。
if (isYoung)
{
Console.WriteLine("是青年!");
}
else
{
Console.WriteLine("不是青年!");
}
}
}
}
C#__输入一个人的年龄,判断是否为青年。(18~40岁)
于 2023-06-07 17:23:17 首次发布