
program to calculate the standard deviation of an array of values.the array elements are read from terminal.use function to calculate standard deviation and mean.

Hi Friend,
Try the following code:
import java.util.*;
public class StandardDeviation{
public double findMean(int array[]){
double total = 0;
for(int i = 0; i < array.length; i++){
total = total + array[i];
}
double mean = total/array.length;
return mean;
}
public void findStandardDeviation(int array[]){
double mean = findMean(array);
System.out.println("Mean is: "+mean);
double d1 = 0;
double d2 = 0;
double sum = 0;
for(int i = 0; i < array.length; i++){
d2 = (mean - array[i])*(mean - array[i]);
d1 = d2 + d1;
}
System.out.println("Standard Deviation: " + Math.sqrt((d1/(array.length-1))));
}
public static void main(String args[]){
Scanner input=new Scanner(System.in);
System.out.println("Enter Array Elements: ");
int array[] = new int[5];
for(int i=0;i<array.length;i++){
array[i]=input.nextInt();
}
StandardDeviation sd = new StandardDeviation();
sd.findStandardDeviation(array);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.