The mean is just totalValue / totalCount
.
To do it as another loop at the end of your existing code:
Start with them both at 0.
long totalValue = 0;
long totalCount = 0;
So you need to loop through all of your word counts doing:
totalValue += wordLength * wordCount;
totalCount += wordCount;
Then at the end you just do:
float mean = (float)totalValue/totalCount;
Alternatively to calculate the mean at the same time as doing the main loop you can do:
totalValue += wordLength;
totalCount += 1;
Each time around the main loop once you have found a word.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…