.Net基础篇_学习笔记_第五天_流程控制while循环003
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 流程语句02 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 int i = 1; 14 string userName = ""; 15 string userPsw = ""; 16 Console.WriteLine("请输入您的用户名:"); 17 userName = Console.ReadLine(); 18 Console.WriteLine("请输入您的密码:"); 19 userPsw = Console.ReadLine(); 20 while (userName!=""||userPsw!="") 21 { 22 while ((userName != "admin" || userPsw != "8888" )&&i<3) 23 { 24 Console.WriteLine("\n您输入的用户名或密码有误,请重新输入。 \n您还可输入{0}次\n",3-i); 25 Console.WriteLine("请再次输入您的用户名:"); 26 userName = Console.ReadLine(); 27 Console.WriteLine("请再次输入您的密码:"); 28 userPsw = Console.ReadLine(); 29 i++; 30 } 31 if((userName == "admin" )&& (userPsw == "8888")&&i<3) 32 { 33 Console.WriteLine("您输入的用户名和密码正确,身份验证成功!"); 34 break; //break关键字的用法,很重要 35 } 36 if (i >= 3) 37 { 38 Console.WriteLine("您输入次数已达到3次,您的账号将会被冻结24小时!"); 39 break; //break关键字的用法,很重要
40 } 41 } 42 Console.ReadKey(); 43 44 } 45 } 46 }
银行用户名和密码输入代码_尝试制作