使用整数数组查找平均值

时间:2016-03-02 00:27:45

标签: arrays vb.net list numbers integer

在我的程序中,我设计了它,以便从文件中读取,解析文件中的任何整数并将它们保存到排序列表中。从那个列表中我创建了三个数组,每个数组都根据列表中的值保存不同的值,除了每个数组的值都会增加1:

示例值:

array 1 will hold the regular values e.g. - 2,3,4,5
array 2 will hold the regular values (+1) - 3,4,5,6
array 3 will hold the regular values (+2) - 4,5,6,7

2,3,4 = 1st user's score
3,4,5 = 2nd user's score
4,5,6 = 3rd user's score

由此我现在想要将这些数组加在一起并除以3得到平均结果,然后保存并与相应的用户一起加入值,但不确定我是否可以直接添加数组。

这是我到目前为止的代码:

Dim basenum As New System.Collections.Generic.List(Of Integer)
Dim num As String
num = Regex.Replace(line, "\D+", "")
For Each lin As String In num
    basenum.Add(Convert.ToInt32(lin))
Next
basenum.Sort()
basenum.Reverse()
For Each element As Integer In basenum
    Console.WriteLine(element)
Next
Dim number1() As Integer
Dim number2() As Integer
Dim number3() As Integer
number1 = basenum.ToArray
For Each element As Integer In number1
    Console.WriteLine(element)
Next
number2 = basenum.ToArray 'insert 2nd numbers into second array
For Each element As Integer In number2
    element += 1
    Console.WriteLine(element)
Next
number3 = basenum.ToArray 'insert 3rd numbers into third array
For Each element As Integer In number3
    element += 2
    Console.WriteLine(element)
Next

数字会很好地进入数组但是我不确定如何将数组加在一起并计算平均数。

任何帮助将不胜感激的人:)

0 个答案:

没有答案