source file  name: MeanStdDemo.java

class MeanSD

{

public double mean(double a[])

{

double sum=0.0;

for(int i=0;i<a.length;i++)

sum=sum+a[i];

return(sum/a.length);

}

public double std_dev(double a[])

{

double x=0.0,sum=0.0;

x=mean(a);

for(int i=0;i<a.length;i++)

sum+=(x-a[i])*(x-a[i]);

return (Math.sqrt(sum/a.length));

}

}

class MeanStdDemo

{

public static void main(String as[])

{

System.out.println("program calculates mean and std deviation of 5 double numbers");

double f[]={35.0,67.0,79.5,14.20,55.75};

MeanSD ob=new MeanSD();

System.out.println("mean is:"+ob.mean(f));

System.out.println("std. deviation is:"+ob.std_dev(f));

}

}

output:

D:\JavaPrograms\ArrayPrograms>javac MeanStdDemo.java

D:\JavaPrograms\ArrayPrograms>java MeanStdDemo

program calculates mean and std deviation of 5 double numbers

mean is:50.29

std. deviation is:23.231581952161587