我正在尝试从我创建的 10 种颜色的数组中打印 5 种随机颜色(颜色可以重复,只要它们是随机的)。我知道我很接近,但我不确定我哪里出错了。
import java.util.Random;
public class RandomColors
{
public static void main (String[] args)
{
Random r = new Random();
String[] colors = {"red","green","blue","yellow","brown","black","white","indigo","orange","purple"};
String[] solution = new String[5];
for(int i = 0; i < solution.length; i++)
{
solution[i] = colors[r.nextInt(10)];
System.out.println(i);
}
}
}
我知道我的问题是我正在尝试打印“i”,但我不确定我应该组合打印什么。
DIEA
皈依舞
慕仙森
相关分类