我有一个快速问题,我正在测试Math.random的功能。我试图将(int) (Math.random()*6)+1
的结果分配给一个数组来存储这些值。但是我收到一个错误,它不是一个声明。有人可能提供一些指导?将math.random赋值给数组
public shoes(int[] pairs)
{
System.out.println("We will roll go through the boxes 100 times and store the input for the variables");
for(int i=0; i < 100; i++)
{
//("Random Number ["+ (i+1) + "] : " + (int)(Math.random()*6));
int boxCount[i] = (int) (Math.random()*6) + 1;
}
}
不要使用'的Math.random()'。 ..它不适合你的目的,很难阅读。使用'随机rand = new Random();'和'rand.nextInt(6)+1;'代替。 –
为什么你declearing int boxCount [i] = ...这样,它没有任何意义。 – loki
你的方法没有返回类型。 –