-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIceCream.java
More file actions
executable file
·34 lines (29 loc) · 870 Bytes
/
IceCream.java
File metadata and controls
executable file
·34 lines (29 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package thinkinjava.test16;
import java.util.Arrays;
import java.util.Random;
public class IceCream {
private static Random rand = new Random(47);
static final String[] FLAVORS = {"njknjk", "2cas", "3casca", "cscs", "c2scs", "dqwdwq"};
public static String[] flavorSet(int n) {
if (n > FLAVORS.length) {
throw new IllegalArgumentException("Set too big");
}
String[] results = new String[n];
boolean[] picked = new boolean[FLAVORS.length];
for (int i = 0; i < n; i++) {
int t;
do {
t = rand.nextInt(FLAVORS.length);
}
while (picked[t]);//ɸѡ���ظ���Ԫ��
results[i] = FLAVORS[t];
picked[t] = true;
}
return results;
}
public static void main(String[] args) {
for (int i = 0; i < 7; i++) {
System.out.println(Arrays.toString(flavorSet(6)));
}
}
}