- #1
Frosty415
- 3
- 0
- Generate 225 samples of size 625 random numbers from U(10,22). For each of these 225 samples calculate the mean.
b) Find the mean of the means.
c) Find the standard deviation of the means.
d) Draw the histogram of the means.
Here's my code: I am unable to print from my method of probabilityMean. Anyone know what's wrong?
package test;
Java:
import java.util.Random;
public class test {
public static double average(int[] x) {
double sum = 0;
for (int j = 0; j < x.length; j++) {
sum += x[j];
}
double average = sum / x.length;
return average;
}
public static double average(double[] x) {
double sum = 0;
for (int j = 0; j < x.length; j++) {
sum += x[j];
}
double average = (sum) / x.length;
return average;
}
public static double probabilityMean(double[] x) {
int count = 0;
double avg = average(x);
if (avg >= 10 && avg <= 11) {
count++;
}
double probab = (float) count / 625;
return probab;
}
public static double standardDeviation(double[] values) {
double deviation = 0.0;
if ((values != null) && (values.length > 1)) {
double mean = average(values);
for (double value : values) {
double delta = value - mean;
deviation += delta * delta;
}
deviation = Math.sqrt(deviation / values.length);
}
return deviation;
}
public static void main(String[] args) {
Random rand = new Random();
double finalmean, sd;
double[] mean = new double[225];
int[][] x = new int[225][625];
for (int j = 0; j < 225; j++) {
for (int k = 0; k < 625; k++) {
x[j][k] = rand.nextInt((22 - 10) + 1) + 10;
}
mean[j] = average(x[j]);
System.out.println("Mean of array" + j + " is " + mean[j]);
}
finalmean = average(mean);
sd = standardDeviation(mean);
System.out.println("Mean of means:" + finalmean + "\nStandard deviation:" + sd);
}
}
Last edited by a moderator: