안녕하세요 여러분, 같은 생일을 가진 사람들의 숫자를 얻으려고합니다.하지만이 솔루션은 작동하지 않습니다.이 프로그램은 0.0 %를 보이고 있습니다. 제발 도와주세요 ...!.비슷한 생일 찾기 구조 데이터
public double calculate(int size, int count) {
int matches = 0;//initializing an integer variable
boolean out = false;
List<Integer> days=new ArrayList<Integer>();// creating arraylist name days of type int
for (int j = 0; j <count; j++) {
for (int i = 0; i < size; i++) {// initializing for loop till less than size
Random rand = new Random(); // creating an object of random function
int Brday = rand.nextInt(364) + 0;//initializing the limit of randomc number chozen
days.add(Brday); //adding values to arraylist
}
for (int l = 0; l < size; l++) {
int temp = l;//assigning value of l to a variable
for (int k = l + 1; k < size; k++) {
if (days.get(k) == temp) {// check statement to check values are same
matches++;//incrementing variable
out = true;
mOut.print("Count does have same birthday" + matches);
break;
} else {
mOut.print("does not have same birthday");
}
}
if (out) {
out = false;
break;
}
}
}
double prob = (double) matches/count;
mOut.print("The probability for two students to share a birthday is " + prob*100 + ".");
return prob;//returning double value of the function
}
@RC. OP는 ==를 객체와 함께 사용하지 않고, ==를 'Integer' 및'int'와 함께 사용하여 자동 언 박싱을 발생시킵니다. –
@ErwinBolwidt 네가 옳아, 나쁘다. –
[수식] (https://en.wikipedia.org/wiki/Birthday_problem)을 사용할 수 없습니까? –