GetCshape/doif/Program.cs

48 lines
1.5 KiB
C#
Raw Permalink Normal View History

2024-12-14 18:08:48 +08:00
using System;
class LogicalAndDemo
{
static void Main()
{
// 提示用户输入年龄
Console.Write("请输入您的年龄: ");
string ageInput = Console.ReadLine();
// 尝试将输入转换为整数类型
int age;
bool isValidAge = int.TryParse(ageInput, out age);
// 提示用户是否同意条款
Console.Write("您是否同意条款? (yes/no): ");
string agreement = Console.ReadLine();
// 判断用户是否同意条款(忽略大小写)
bool isAgreed = agreement.ToLower() == "yes";
/*
* 使 `&&`
* 1.
* 2.
* 3. 18100
*
* true
*
*/
if (isValidAge && isAgreed && age >= 18 && age <= 100)
{
Console.WriteLine("欢迎加入!");
}
else
{
Console.WriteLine("抱歉,您无法加入。");
}
/*
*
* - `&&`
* - false
* - true
*/
}
}