Code
for (int i = 0; i < 10; )
{
string str = Console.ReadLine();
int num;
if (int.TryParse(str, out num) == false)
{
Console.WriteLine("输入的不是数字,请重新输入!");
}
else
{
{
if (num % 2 == 0)
{
Console.WriteLine("偶数");
}
else
{
Console.WriteLine("奇数");
}
}
}
i++;
}
for (int i = 0; i < 10; )
{
string str = Console.ReadLine();
int num;
if (int.TryParse(str, out num) == false)
{
Console.WriteLine("输入的不是数字,请重新输入!");
}
else
{
{
if (num % 2 == 0)
{
Console.WriteLine("偶数");
}
else
{
Console.WriteLine("奇数");
}
}
}
i++;
}
Code
int temp=0;
while (temp == 0)
{
string input = Console.ReadLine();
try
{
int num = int.Parse(input);
temp++;
}
catch
{
Console.WriteLine("您输入的不是数字,请重新输入!");
temp = 0;
}
}
int temp=0;
while (temp == 0)
{
string input = Console.ReadLine();
try
{
int num = int.Parse(input);
temp++;
}
catch
{
Console.WriteLine("您输入的不是数字,请重新输入!");
temp = 0;
}
}