Statistics very basic

Discussion in 'Java' started by Pierre8r, May 2, 2008.

  1. Pierre8r

    Pierre8r Guest

    Hello,

    I have a array like this :

    double[] array = { 10.1, 34.0, 15.0, 22.5, 24.2, 31.0, 32.0, 37.0 };

    I search to know
    how many values there are :
    <10
    how many values there are between :
    >= 10 and < 20

    how many values there are between :
    >= 20 and < 30

    how many values there are :
    >= 30


    Regards,

    Pierre8r
     
    Pierre8r, May 2, 2008
    #1
    1. Advertising

  2. Pierre8r

    Christian Guest

    Pierre8r schrieb:
    > Hello,
    >
    > I have a array like this :
    >
    > double[] array = { 10.1, 34.0, 15.0, 22.5, 24.2, 31.0, 32.0, 37.0 };
    >
    > I search to know
    > how many values there are :
    > <10
    > how many values there are between :
    > >= 10 and < 20

    > how many values there are between :
    > >= 20 and < 30

    > how many values there are :
    > >= 30

    >
    > Regards,
    >
    > Pierre8r

    Homework is meant to be done by you. It should help you to learn the
    basics of java.

    2 tips:
    1. array you can access the i-th index of the array..
    2. You will want to use a for-loop to get all positions in the array
     
    Christian, May 2, 2008
    #2
    1. Advertising

  3. Pierre8r

    Pierre8r Guest

    Christian a écrit :
    >> Pierre8r

    > Homework is meant to be done by you. It should help you to learn the
    > basics of java.
    >


    The true question is :
    How to use :
    package org.apache.commons.math.stat; to do the job ?

    Cant org.apache.commons.math.stat do this kind of stuff ?
    It's more about how to use org.apache.commons.math.stat, because I will
    need other functions from this API.
    This question is just a start.

    I have already try to use org.apache.commons.math.stat, but without success.

    I have try Frequency but without success.

    > 2 tips:
    > 1. array you can access the i-th index of the array..
    > 2. You will want to use a for-loop to get all positions in the array
    >
     
    Pierre8r, May 2, 2008
    #3
  4. "Christian" <> wrote in message
    news:481b5fea$0$25892$...
    > Pierre8r schrieb:
    >> Hello,
    >>
    >> I have a array like this :
    >>
    >> double[] array = { 10.1, 34.0, 15.0, 22.5, 24.2, 31.0, 32.0, 37.0 };
    >>
    >> I search to know
    >> how many values there are :
    >> <10
    >> how many values there are between :
    >> >= 10 and < 20

    >> how many values there are between :
    >> >= 20 and < 30

    >> how many values there are :
    >> >= 30

    >>
    >> Regards,
    >>
    >> Pierre8r

    > Homework is meant to be done by you. It should help you to learn the
    > basics of java.
    >
    > 2 tips:
    > 1. array you can access the i-th index of the array..
    > 2. You will want to use a for-loop to get all positions in the array


    I'll just add to that, you only need to look at each value once. Also, for
    this particular case, use of some functions in java.lang.Math will avoid the
    use of conditionals.

    AHS
     
    Arved Sandstrom, May 2, 2008
    #4
  5. Pierre8r

    Arne Vajhøj Guest

    Arne Vajhøj, May 2, 2008
    #5
  6. Re: Statistics very basic

    for each one create a counter and loop through the array then if the
    number meats the required pram increment the counter

    //<10
    double[] array = { 10.1, 34.0, 15.0, 22.5, 24.2, 31.0, 32.0, 37.0 };
    int count = 0;
    for(double d : array)
    {
    if(d > 10)
    {
    count++;
    }
    }
     
    Chase Preuninger, May 2, 2008
    #6
  7. Pierre8r

    Pierre8r Guest

    Thaks to Chase, for the loop tip.

    I have find something it seen work.
    If you have something better, please post.

    Pierre8r


    import org.apache.commons.math.stat.Frequency;

    public class TestStats001 {

    /**
    * @param args
    */

    public static void main(String[] args) {
    Frequency frequency = new Frequency();
    double[] population = { 10.1, 34.0, 10.0, 22.5, 24.2, 1.0, 32.0, 37.0 };
    double[] caracteres = { 10.0, 20.0, 30.0 };
    boolean find;

    for (double p : population) {
    int i;
    find = false;
    for (i = 0; i < caracteres.length; i++) {
    if (p < caracteres) {
    frequency.addValue(i);
    find = true;
    break;
    }
    }
    if (find == false) {
    frequency.addValue(i);
    }
    }

    for (int i = 0; i < caracteres.length + 1; i++) {
    System.out
    .println("Caractère " + i + " : " + frequency.getCount(i));
    }
    for (int i = 0; i < caracteres.length + 1; i++) {
    System.out
    .println("Pourcentage " + i + " : " + frequency.getPct(i));
    }
    }
    }
     
    Pierre8r, May 5, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    499
    Raymond Hettinger
    Jul 27, 2003
  2. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,680
    Merrill & Michele
    Oct 19, 2004
  3. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    446
    jacob navia
    Oct 17, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    526
    Dave Thompson
    Feb 14, 2005
  5. olivier.melcher

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,329
Loading...

Share This Page