Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: How I generate the postive total mean from this java code.It geneate negative mean approaches to infinity

1. ## How I generate the postive total mean from this java code.It geneate negative mean approaches to infinity

First, it generates ten random numbers from normal distribution and calculates the mean of ten numbers and stores this in an ArrayList. Similarly, it does this for ten lac times. Then, it gives the total mean of ten lac values which is a positive value like this: 0.000142. But it generates negative values as it approaches to infinity. I want positive values... How I will achieve this task? Someone tell me, thanks
```package statistics;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import org.apache.commons.math3.distribution.NormalDistribution;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;

public class NewClass {

public static void main(String[] args) {

double mean=0.0;
ArrayList store_mean=new ArrayList();
Iterator it;
DescriptiveStatistics stats = new DescriptiveStatistics();
Random gaussian = new Random();
for(int i=1; i<=1000000; i++)
{

for (int idx = 1; idx <= 10; ++idx)
{
// System.out.println("Generated : " + gaussian.nextGaussian());

}
mean =  stats.getMean();
stats.clear();
}
it=store_mean.iterator();
while(it.hasNext())
{

}
mean=stats.getMean();

System.out.println("Total Mean="+mean);

}```

2. ## Re: How I generate the postive total mean from this java code.It geneate negative mean approaches to infinity

Might it be that you get a value overflow for the range of valid integer values?