int max = 0;
string input = "";
int number = 0;
int flag = 0;
do
{
try
{
Console.WriteLine("请输入一个数:");
input = Console.ReadLine();
number = Convert.ToInt32(input);
if (number > max)
{
max = number;
}
}
catch
{
if (input != "end")
{
Console.WriteLine("输入错误");
input = "end";
}
}
}
while (input != "end");
Console.WriteLine("程序最大值为{0}。", max);
Console.ReadKey();
int max = 0;
string input = "";
int number = 0;
int flag = 0;
do
{
try
{
Console.WriteLine("请输入一个数:");
input = Console.ReadLine();
number = Convert.ToInt32(input);
if (number > max)
{
max = number;
}
}
catch
{
if (input != "end")
{
Console.WriteLine("输入错误");
input = "end";
}
}
}
while (input != "end");
if (input != "end")
{
Console.WriteLine("程序最大值为{0}。", max);
}
Console.ReadKey();