Consider the following code snippet:
int[] dataSet = {1,2,3,4};
int total = 0;
for(int temp : dataSet){
total += temp;
}
double mean = (total / dataSet.length);
System.out.println(mean);
I expected this to output 2.5, as that is the mean of 1,2,3,4. Instead, it printed 2.0. Why is this and how can I fix it?