Click here to Skip to main content
15,877,591 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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();
            l.add(v);
        }
         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
Comments
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.

1 solution

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

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



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