namespace P03
{
class Program
{
static void Main(string[] args)
{
Test04();
}
public static void Test04()
{
/* 编一个程序,输入用户名和密码,实现用户登录程序的功能,至多允许输入三次,超过三次不允许登录并退出程序 */
string uid = "";
string pwd = "";
//Console.WriteLine("请输入账号:");
//uid = Console.ReadLine();
//Console.WriteLine("请输入密码:");
//pwd = Console.ReadLine();
int i = 0;
while (true)
{
Console.WriteLine("请输入账号:");
uid = Console.ReadLine();
Console.WriteLine("请输入密码:");
pwd = Console.ReadLine();
//int i = 0;
if (uid == "sa" && pwd == "sa")
{
Console.WriteLine("你输入的账号密码正确!");
break;
}
else
{
i++;
Console.WriteLine("账号密码错误");
if (i >= 3)
{
Console.WriteLine("错误超过3次,强制退出!");
Console.ReadLine();
break;
}
}
}
}
}
}
自写的--C#基础篇十小练习04
最新推荐文章于 2019-09-26 07:00:37 发布