(adsbygoogle = window.adsbygoogle || []).push({}); a) Find the simulated probability that the mean is between 10 and 11.

- 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 whats wrong?

package test;

Mod edit: To deal with the problem of i index turning to I and being treated as italics tags, I changed the index i to j, and in one method with both i and j, changed i to j and j to k.Code (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);

}

}

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Confused java HW code

Loading...

Similar Threads - Confused java code | Date |
---|---|

Python Recursion in python functions -- confusion | Feb 5, 2017 |

This error (Java) is confusing me | Mar 5, 2013 |

Confused about Java and Glassfish | Aug 27, 2012 |

JAVA - composition/aggregation confusion | Nov 4, 2011 |

Java: Confusing while loop | Nov 9, 2009 |

**Physics Forums - The Fusion of Science and Community**