How to calculate standard deviation using JAVA

arrays, java, standard-deviation

Solution

  calculate mean of array.

  loop through values

       array value = (indexed value - mean)^2    

  calculate sum of the new array.

  divide the sum by the array length

  square root it 

edited:

I'll show you how to loop through the array and everything is pretty much this same step just with a different calculation.

// calculating mean.

int total = 0;

for(int i = 0; i < array.length; i++){
   total += array[i]; // this is the calculation for summing up all the values
}

double mean = total / array.length;

edit2:

After reading your code, the part you are doing wrong is that you are not looping through the values and subtracting it with average correctly.

aka this part.

eleven = average_total - mean; eleven = Math.pow(average_total,average_total);

you need to do this.

for(int i = 0; i < array.length; i++){
   array[i] = Math.pow((array[i]-mean),2)
}

essentially you need to change every value in the array with newvalue = oldvalue - mean(average).

then calculate the sum... then square root that.

Problem

I'm very new here, at the moment I am trying to calculate standard deviation with Java (I have googled it haha) but I am having a lot of issues on getting it working I have ten values that are inputed by a user which I then have to calculate the standard deviation of my understanding so far thanks to people who have replied is I find the mean of the array then complete the calculations ``` double two = total[2]; double three = total[3]; double four = total[3]; double five = total[4]; double six = total[6]; double seven = total[7]; double eight = total[8]; double nine = total[9]; double ten = total[10]; double eleven = average_total; mean = one + two + three + four + five + six + seven + eight + nine + ten + eleven; mean = mean/11; //one = one - mean; //System.out.println("I really hope this prints out a value:" +one); */ //eleven = average_total - mean; //eleven = Math.pow(average_total,average_total); //stand_dev = (one + two + three + four + five + six + seven + eight + nine + ten + eleven); //stand_dev = stand_dev - mean; // stand_dev = (stand_dev - mean) * (stand_dev - mean); // stand_dev = (stand_dev/11); // stand_dev = Math.sqrt(stand_dev); ``` I already have my data that is stored in an array of 10 values but I am not too sure how to print the data out of the array then do the calculations with out having to store the enter code here data some where else that I have manipulated Thank you for your time, much appreciated :)

Original source