15,905,607 members
See more:
For exp we have this sequence of numbers:
10 25 50 50
p(10) = 25% and 10!= p(10) =25 so false
p(25) = 25% and 25 == 25 so true
p(50) = 50% and 50 == p(50) =50 true

the number of true is 2 so p(true) is 75%

i want to print 75% (the number of true, i mean count the proba when the number equal its probability of apperance in the sequence )

here is my essaie :

What I have tried:

Java
```import java.util.*;
import java.io.*;
import java.math.*;

/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class proba {

public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int s=0;
int p=1;
int ss=0;
int N = in.nextInt();
List<Integer> l = new ArrayList<>();
for (int i = 0; i < N; i++) {
int v = in.nextInt();
}
ListIterator<Integer> it = l.listIterator();
while(it.hasNext()){
Integer i = it.next();
while(it.hasNext()){
if(it.equals(i))
s++;
}

p=(s/N)*100;
if (p == i)
ss++;

}

System.out.print((ss/N)*100);

}
}```
Posted
Updated 6-Dec-17 22:12pm
v2
OriginalGriff 7-Dec-17 4:06am
And?
What is the problem?
What does it do that you didn't expect, or not do that you did?
What help do you need?
CodeWraith 7-Dec-17 4:27am
the number of true is 2

That explains everything.

## Solution 1

To compute the probability of every number you must count its occurrences in the list. The algorithm is simpler provided the list is ordered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 BupeChombaDerrick 40 Dave Kreskowiak 38 Graeme_Grant 10 Patrice T 10 Pete O'Hanlon 10
 Pete O'Hanlon 1,750 OriginalGriff 1,317 Richard Deeming 550 Dave Kreskowiak 473 Richard MacCutchan 355

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900