using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//不断要求用户输入一个数字(假定用户输入的都是正整数),当用户输入end的时候显示刚才输入的数字中的最大值
string strnumber = "";
int max = 0;
do
{
Console.WriteLine("请用户输入一个正整数");
strnumber = Console.ReadLine();
if (strnumber != "end")
{
try
{
int number = Convert.ToInt32(strnumber);
if (number > max)
{
max = number;
}
}
catch
{
Console.WriteLine("这个程序错误");
}
}
else
{
Console.WriteLine("刚才输入数字的最大值{0}",max);
}
} while (strnumber != "end");
Console.ReadKey();
}
}
}
![](https://img.haomeiwen.com/i14500636/0369ee2fce39323f.png)
网友评论