int a=0 ;
int b=0;
bool c = true;
do
{
try
{
Console.WriteLine("请输入一个数字");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入二个数字");
b = Convert.ToInt32(Console.ReadLine());
}
catch
{
Console.WriteLine("你输入的不是数字,重新输入");
}
c = false; }
while (c);
Console.WriteLine(a+b);
Console.ReadKey();
}
}
}
要求用户输入两个数字 如果第一个是数字 第二个不是 提示用户输入第二数字 并输出两个数的和c#
int b=0;
bool c = true;
do
{
try
{
Console.WriteLine("请输入一个数字");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入二个数字");
b = Convert.ToInt32(Console.ReadLine());
}
catch
{
Console.WriteLine("你输入的不是数字,重新输入");
}
c = false; }
while (c);
Console.WriteLine(a+b);
Console.ReadKey();
}
}
}
要求用户输入两个数字 如果第一个是数字 第二个不是 提示用户输入第二数字 并输出两个数的和c#
bool firstWrong=false,secondWrong=false;
int a=0,b=0;
do
{
Console.WriteLine("输入第一个数字:");
try
{
a=ConvertToInt32(Console.ReadLine());
firstWrong=false;
}
catch
{
Console.WriteLine("数字格式不正确");
firstWrong=true;
}
}whiel(firstWrong);do
{
Console.WriteLine("输入第二个数字:");
try
{
a=ConvertToInt32(Console.ReadLine());
secondWrong=false;
}
catch
{
Console.WriteLine("数字格式不正确");
secondWrong=true;
}
}whiel(secondWrong);
Console.WriteLine(a+b);
Console.ReadKey();