【发布时间】:2016-02-21 10:32:53
【问题描述】:
好的,所以我需要生成 7 个介于 1 和 100 之间的随机数,并将最大值打印在屏幕上。但是,当我编译这段代码时:
public class ArrayofTemperatures
{
public static void main(String[] args)
{
double [] temp = new double [7];
int index;
double max;
double random = Math.random() * 100 + 1;
temp[0] = random.nextDouble();
max = temp[0];
for (index = 1; index < temp.length; index++)
{
temp[index] = random.nextDouble();
if (temp[index] > max)
max = temp[index];
}
System.out.println("The highest score is: " + max);
}
}
我得到这两个错误:
ArrayofTemperatures.java:12:错误:无法取消引用双精度 temp[0] = random.nextDouble();
ArrayofTemperatures.java:16:错误:无法取消引用双精度 temp[index] = random.nextDouble();
【问题讨论】:
标签: java arrays random numbers