vendredi 15 juillet 2016

Birthday probability takes so much time on java "android studio"

I'm taking a course about java for android and this problem is required to solve birthday problem this code works fine on intelliji but when i start testing it on android studio it doesn't stop loading

public double calculate(int size, int count) {
    // TODO -- add your code here
    int demonstrator=0;
    double percent;
    //looping through each simulation
    for (int i=0;i<count;i++){
        ArrayList<Integer> days=new ArrayList<>();
        ArrayList<Integer> days2=new ArrayList<>();
        Random rnd=new Random(i);
        //adding birthdays to the list
        for (int x=0;x<size;x++){
            days.add(rnd.nextInt(364)+1);
        }
        //comparing if the date already exists
        for (int day:days){
            if (days2.contains(day)){
                demonstrator++;
                break;
            }else {
                days2.add(day);
            }
        }
    }
    percent=demonstrator*100.0/count;
    return percent ;}

Aucun commentaire:

Enregistrer un commentaire