Java程序创建一个包含4个人名的字符串数组(人名自定),然后从数组中随机选出其中3个且不重复

2025-02-24 08:02:32
推荐回答(1个)
回答1:

啊?这是一个算法题。。

经过5秒钟的沉思

我打开了我的eclipse

		String[] test={"70","million","来自","百度知道"};
Boolean[] abc={false,false,false,false};
int temp;
Random random=new Random();
int i=0;
while (i < 3) {
temp=random.nextInt(4);
if (!abc[temp]) {
System.out.println(test[temp]);
abc[temp]=true;
i++;
}
}

写下了一堆莫名的东西,啊?

一运行,

居然和楼主的问题的答案一样。