Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Statistics very basic

Reply
Thread Tools

Statistics very basic

 
 
Pierre8r
Guest
Posts: n/a
 
      05-02-2008
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
 
Reply With Quote
 
 
 
 
Christian
Guest
Posts: n/a
 
      05-02-2008
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[i] 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

 
Reply With Quote
 
 
 
 
Pierre8r
Guest
Posts: n/a
 
      05-02-2008
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[i] 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
>

 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      05-02-2008
"Christian" <(E-Mail Removed)> wrote in message
news:481b5fea$0$25892$(E-Mail Removed)...
> 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[i] 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


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-02-2008
Pierre8r wrote:
> 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.


Read the docs:

http://commons.apache.org/math/api-1...e-summary.html

Arne
 
Reply With Quote
 
Chase Preuninger
Guest
Posts: n/a
 
      05-02-2008
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++;
}
}
 
Reply With Quote
 
Pierre8r
Guest
Posts: n/a
 
      05-05-2008
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[i]) {
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));
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I found some very odd behaviour in Python's very basic types Sunjay Varma Python 4 03-10-2011 05:05 PM
A very **very** basic question mdh C Programming 57 09-26-2008 03:25 PM
very very basic question aghazalp Python 6 04-02-2006 09:35 PM
Very very very basic question Peter C Programming 14 02-14-2005 09:46 AM
Quick Book file access very very very slow Thomas Reed Computer Support 7 04-09-2004 08:09 PM



Advertisments