美文网首页
2018-11-14

2018-11-14

作者: be1058558528 | 来源:发表于2018-11-14 22:32 被阅读0次

    练习3:

    不断要求用户输入一个数字(假定用户输入的都是正整数),当用户输入end的时候显示刚才输入的数字中的最大值

    static void Main(string[] args)

            {

                string strNumber = "";

                int max = 0;

                while (strNumber != "end")

                {

                    Console.WriteLine("请输入一个数字,输入end,我们将显示你输入的数字中的最大值");

                    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);

                    }

                }

                Console.ReadKey();

            }

    相关文章

      网友评论

          本文标题:2018-11-14

          本文链接:https://www.haomeiwen.com/subject/eohdfqtx.html