gpt4 book ai didi

java - 必需 : double [] found: no arguments

转载 作者:行者123 更新时间:2023-12-02 12:37:10 28 4
gpt4 key购买 nike

代码:

 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;
}

忽略字符串内的其他内容(最小值、最大值和范围),但对于这一行,

 String output = "Class average:" + calculateAverage() + "\n" + "Maximum mark:" +  
calculateMaximum() + "\n" +"Minimum mark:" + calculateMinimum() + "\n" + "Range of
marks:" + range;

我收到错误:

required: double []
found: no arguments

为什么会出现此错误?我应该更改什么?

最佳答案

您以这种方式调用calculateAverage 方法:calculateAverage(),不带任何参数。但该方法是这样声明的:

private double calculateAverage(double [] marks) 

因此,它需要一个 double[] 类型的参数,但您无需传递任何内容。

关于java - 必需 : double [] found: no arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10789251/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com