*/
public static double ranNumber(double [] gradeArray) {
double rN = 0;
for (int i = 0; i < gradeArray.length; i++) {
rN = 55 + Math.random() * (100 - 55) + 1; //this section is to generate a # between 55-100.
}
return rN;
}
/**
*
* @param input
*
*/
public static void outputArray(double [] input) { // this is where I want the random # to go and to later convert to letter grade.
for (int count = 1; count <= input.length; count++) {
System.out.printf("Grade %d: %.2f is a ", count+1 , input[count]);
}
}
好的,所以我只发布了这两种方法,因为我想要尝试做的是将随机数输入outputArray,这样我就可以将双重转换为字母等级。我的输出应该是这样的,&#34;等级1:93.23是A - &#34;。
答案 0 :(得分:0)
据我所知,你想要生成一系列随机成绩。您的原始函数不需要传入数组参数,它应该返回一个。
public static double[] ranNumber(int len) {
double[] rN = new double[len];
for (int i = 0; i < len; i++) {
rN[i] = 55 + Math.random() * (100 - 55) + 1; //this section is to generate a # between 55-100.
}
return rN;
}
然后,在outputArray
中调用该方法并循环它。或者将其作为main
警告... int count = 1; count <= input.length
... input[count]
会抛出异常