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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

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

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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());
             stats.addValue(gaussian.nextGaussian());
     
     
         }
         mean =  stats.getMean();
              stats.clear();
              store_mean.add(mean);
         }
           it=store_mean.iterator();
            while(it.hasNext())
           {
               stats.addValue((double) it.next());
     
           }
            mean=stats.getMean();
     
     
         System.out.println("Total Mean="+mean);
     
     
     
     
     
     }


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default 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?

Similar Threads

  1. Could someone check my code out for me? (I'm a total newb)
    By Robertooooooooo in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 7th, 2014, 12:27 PM
  2. Replies: 7
    Last Post: May 8th, 2013, 02:33 PM
  3. infinity output and cannot return value
    By Crext in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 29th, 2013, 11:48 PM
  4. What's wrong with my code? (generate sequences of numbers using a stack)
    By mescoff in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 18th, 2012, 09:12 AM
  5. [SOLVED] What's wrong with my code?? (Total beginner)
    By TheProf in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 6th, 2012, 02:41 PM

Tags for this Thread