Hey. I'm having some difficulty in Array lists. I have to find the average of all the numbers in an array list. That's my first task. My second one is to find the mode of all the numbers, meaning the number that shows up the most. And the third one is to find a standard deviation, which I will get to later.
Anyway, right now I'm doing Average.
import java.util.ArrayList;
public class Statistics
{
public static void main(String args[])
{
ArrayList <Integer> intList = new ArrayList <Integer>();
int avgTemp = 0;
int count1 = 0;
for (int i = 0; i < intList.size(); i++)
{
int b = (int) (Math.random() * 10);
intList.set(i, b);
}
for (int i = 0; i < intList.size(); i++)
{
int j = intList.get(i);
avgTemp += j;
count1++;
}
System.out.println("The average of all the values in the Array List is " + avgTemp/count1);
}
}
That's what I have so far. The first for loop makes a random array list, but I think it's wrong. And the second one will store all the integers of the arrayList into avg temp, and then I'll get the average in my output statement. But it doesnt work.