static void Main(string[] args)
{
Console.WriteLine("你是否要关机");
string s = ReadAmswer();
if (s == "y")
{
Console.WriteLine("关机");
}
else
{
Console.WriteLine("不关机");
}
}
public static string ReadAmswer()
{
string result = "";
do
{
result = Console.ReadLine();
if (result != "y" || result != "n")
{
Console.WriteLine("你输入的不正确请重新输入");
}
} while (result != "y" || result != "n");
return result;
} 作者: 徐荣权 时间: 2013-2-25 18:11
static void Main(string[] args)
{
Console.WriteLine("你是否要关机");
string s = ReadAmswer();
if (s == "y")
{
Console.WriteLine("关机");
}
else
{
Console.WriteLine("不关机");
}
}
public static string ReadAmswer()
{
string result = "";
do
{
result = Console.ReadLine();
if (result != "y" && result != "n")
{
Console.WriteLine("你输入的不正确请重新输入");
}
} while (result != "y"&& result != "n");
return result;
复制代码
这样就不会有问题了,你方法里应该使用&& 而不是||作者: xiaoxiang_04 时间: 2013-2-25 18:40
if (result != "y" || result != "n")无论你输入什么,这都是true啊
改 if (result != "y"&&result != "n")作者: 戴鑫凯 时间: 2013-2-25 22:01
你好 , if (result != "y" || result != "n")
{
Console.WriteLine("你输入的不正确请重新输入");
}