C#第十一次作业2

2018-12-06  本文已影响0人  亻尔亻也

完成以下要求:

int[] shuru = new int[6];

            int max = 0;

            try

            {

                for (int i = 0; i < shuru.Length; i++)

                {

                    Console.WriteLine("请输入第{0}个整数",i+1);

                    shuru[i] = Convert.ToInt32(Console.ReadLine());

                }

                for (int i = 0; i < shuru.Length-1; i++)

                {

                    for (int j = 0; j < shuru.Length-1-i; j++)

                    {

                        if (shuru[j]>shuru[j+1])

                        {

                            max = shuru[j];

                            shuru[j] = shuru[j+1];

                            shuru[j+1] = max;

                        }

                    }

                }

                for (int i = 0; i < shuru.Length; i++)

                {

                    Console.Write("{0}\t",shuru[i]);

                }

            }

            catch

            {

                Console.WriteLine("输入有误请重新输入");

            }

            Console.ReadKey();

上一篇 下一篇

猜你喜欢

热点阅读