必需:double []找到:无参数 [英] required: double [] found: no arguments
本文介绍了必需:double []找到:无参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
ArrayList <Integer> marks = new ArrayList();
String output = "Class average:" + calculateAverage() + "\n" + "Maximum mark:" +
calculateMaximum() + "\n" +"Minimum mark:" + calculateMinimum() + "\n" + "Range of
marks:" + range;
analyzeTextArea.setText(output);
private double calculateAverage(double [] marks) {
double sum = 0;
for (int i=0; i< marks.length; i++) {
sum += marks[i];
}
return sum / marks.length;
}
忽略字符串中的其他内容(最小,最大和范围),但对于此行,
Disregard the other things inside the string (minimum, maximum, and range) but for this line,
String output = "Class average:" + calculateAverage() + "\n" + "Maximum mark:" +
calculateMaximum() + "\n" +"Minimum mark:" + calculateMinimum() + "\n" + "Range of
marks:" + range;
我收到一个错误:
必填:双[]
找不到:没有参数
required: double []
found: no arguments
为什么会出现此错误,我应该更改什么?
Why do I get this error and what should I change?
推荐答案
您正在以这种方式调用calculateAverage方法:calculateAverage()
,不带任何参数.但是方法是这样声明的:
You're calling the method calculateAverage this way: calculateAverage()
, without any argument. But the method is declared this way:
private double calculateAverage(double [] marks)
因此,它需要一个类型为double[]
的参数,但是您什么也不传递.
It thus needs one argument of type double[]
, but you don't pass anything.
这篇关于必需:double []找到:无参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文