My program calculates/determines and displays various statistical data from a set of numbers stored in an array. One of the methods I need to implement is one that will calculate the standard deviation. I'm having a real heck of a time trying to get this to work correctly, because I am consistently getting incorrect results even after changing some of the code and looking at examples elsewhere on the Web. Could anyone please give me some suggestions/pointers? I have a method called mean as well, if that helps. My code for the stddev (standard deviation) is below:
public static double stddev(double[] nums)
{
double standdev=0;
double x=0;
double x2=0;
for(int i=0; i<nums.length; i++)
{
x+=nums[i];
x2+=Math.pow(nums[i], 2);
}
standdev=(Math.sqrt(x2-((x)*(x)/nums.length))/(nums.length-1));
return standdev;
}
Thank you!

New Topic/Question
Reply




MultiQuote




|