//《thinking in java》中的一个例题,里面红色部分我还没还明白
//谁给我解释一下?
//程序大概就是给冰激凌调处20种味道的样子;
package myPakage;
public class ReturnStringArray {
static String[] flav=
{
"chocolate","strawberry",
"vanilla fudge swirl","mint chip",
"mocha almond fudge","rum raisin",
"praline cream","mud pie"
};
static String[] flavorSet(int n)
{
n=Math.abs(n)%(flav.length+1);//这啥意思啊
String[] results=new String[n];
boolean[] picked=new boolean[flav.length];
for(int i=0;i<n;i++)
{
int t;
do
t=(int)(Math.random()*flav.length);
while(picked[t]);
results[i]=flav[t];
picked[t]=true;
}
return results;
}
public static void main(String[] args)
{
for(int i=0;i<20;i++)
{
System.out.println("flavorSet("+i+")=");
String[] f1=flavorSet(flav.length);
for(int j=0;j<f1.length;j++)
{
System.out.println("\t"+f1[j]);
}
}
}
}