public double variance() {
if (data.length == 0) {
return Double.NaN;
} else {
for (int i = 0; i < data.length; i++) {
double temp = average() - data[i];
Math.pow(temp, 2);
return temp / data.length;
}
}
}
This is a snippet of code from my program, Stat. I am coding on eclipse and it tells me not only to add a return statement, but that the i++ in the for loop is "dead code" (this is the first time I am encountering that term). basically what I am trying to do is return Double.NaN for an empty array, then for any other array subtract the data at position i from the average (first line under for loop). This value is then squared (second line under for loop). Since variance is the average of all these "temp" values, the return statement underneath returns temp / data.length. I can tell I am doing this wrong, if anyone can give me a couple hints or point me in the right direction thatd be awesome.