MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / flavorSet

Method flavorSet

arrays/IceCreamFlavors.java:17–31  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

15 "Praline Cream", "Mud Pie"
16 };
17 public static String[] flavorSet(int n) {
18 if(n > FLAVORS.length)
19 throw new IllegalArgumentException("Set too big");
20 String[] results = new String[n];
21 boolean[] picked = new boolean[FLAVORS.length];
22 for(int i = 0; i < n; i++) {
23 int t;
24 do
25 t = rand.nextInt(FLAVORS.length);
26 while(picked[t]);
27 results[i] = FLAVORS[t];
28 picked[t] = true;
29 }
30 return results;
31 }
32 public static void main(String[] args) {
33 for(int i = 0; i < 7; i++)
34 show(flavorSet(3));

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected