int sum = 0, maxsum = 0;
double avg;
//声明随机数对象
Random r = new Random();
ArrayList list = new ArrayList();
while (list.Count < 10)
{
int i = r.Next(1, 21);
//筛选重复项
if (!list.Contains(i))
{
list.Add(i);
}
}
//排序
list.Sort();
//遍历输出
foreach (object o in list)
Console.Write(o + " ");
for (int j = 1; j < 9; j++)
{
sum = (int)list[j];
maxsum += sum;
sum = 0;
}
avg = maxsum / 8.0;
Console.Write("\n最小值:" + list[0] + " 最大值:" + list[9] + " 平均值:" + avg + "" + " 总和:" + maxsum + "");
Console.ReadLine();
c#ArrayList数组的简单使用
最新推荐文章于 2023-07-14 22:15:26 发布