1 2 //要求用户输入用户名密码,用户名只要不是admin密码不是888888提示失败 3 string name = ""; 4 string mi = ""; 5 while (name != "admin" || mi != "888888") 6 { 7 Console.WriteLine("请输入用户名"); 8 name = Console.ReadLine(); 9 Console.WriteLine("请输入密码"); 10 mi = Console.ReadLine(); 11 } 12 Console.WriteLine("登录成功"); 13 Console.ReadKey();
1 //输入班级人数,然后依次输入学员成绩,计算班级学员的平均成绩和总成绩 2 Console.WriteLine("输入班级人数"); 3 int renshu = Convert.ToInt32(Console.ReadLine()); 4 int i = 1; 5 int zong = 0; 6 while (i <= renshu) 7 { 8 Console.WriteLine("请输入第{0}个学员的成绩",i); 9 int fenshu= Convert.ToInt32(Console.ReadLine()); 10 zong += fenshu; 11 i++; 12 } 13 Console.WriteLine("{0}个人的班级总成绩是{1},平均成绩是{2}", renshu, zong, zong / renshu); 14 Console.ReadKey();
1 string huida = ""; 2 do 3 { 4 Console.WriteLine("老师我唱的可以吗"); 5 huida = Console.ReadLine(); 6 } while (huida=="no"); 7 Console.WriteLine("可以"); 8 Console.ReadKey(); 9