标签:
用集合代替数组:
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查询多为数组:
???
标签:
原文地址:http://www.cnblogs.com/liuyudong0825/p/4719479.html