Statistics very basic

P

Pierre8r

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
 
C

Christian

Pierre8r said:
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
 
P

Pierre8r

Christian a écrit :
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
 
A

Arved Sandstrom

Christian said:
Pierre8r said:
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
 
C

Chase Preuninger

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++;
}
}
 
P

Pierre8r

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));
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top