Cristiano Magro
2025-10-05 12a2fa369bebf06753654ae56d607465419b0553
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class CouponCollector {
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        boolean[] trovato = new boolean[n];
        int distinti = 0;
        int tentativi = 0;
 
        while (distinti < n) {
            int r = (int) (Math.random() * n);
            tentativi++;
            if (!trovato[r]) {
                trovato[r] = true;
                distinti++;
            }
        }
 
        System.out.println(tentativi + " tentativi");
    }
}