码迷,mamicode.com
首页 > 其他好文 > 详细

集合,ArrayList

时间:2015-08-11 00:05:11      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

用集合代替数组:

            Console.Write("请输入人数:");
            int renshu = int.Parse(Console.ReadLine());
         ArrayList chengji = new ArrayList();
            if (renshu >= 5)
            {
                for (int h = 1; h <= renshu; h++)
                {
                    Console.Write("请输入第" + h + "个人成绩");
                    chengji.Add(int.Parse(Console.ReadLine()));
                }
                chengji.Sort();
                foreach (int a in chengji) 
                {
                    Console.Write(a+" ");
                }
                
                int he = 0;
                for (int i = 0; i <= renshu - 1; i++)
                {
                    he = he + (int)chengji[i];
                }
                double pj = (he - (int)chengji[0] - (int)chengji[1] - (int)chengji[renshu - 2] -(int)chengji[renshu - 1] / (renshu - 4));
                Console.Write("去掉两个最低分"+chengji[0]+""+chengji[1]+"去掉两个最高分"+chengji[renshu - 2]+""+chengji[renshu - 1]+"最后的成绩是:"+pj);

            }
            else
            {
                Console.WriteLine("您输入的人数要大于等于5!!!");
            }
            Console.ReadLine();

foreach查询多为数组:

???

集合,ArrayList

标签:

原文地址:http://www.cnblogs.com/liuyudong0825/p/4719479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!