required: double [] found: no arguments

前端 未结 4 898
自闭症患者
自闭症患者 2021-01-14 20:38

Code:

 ArrayList  marks = new ArrayList();

 String output = \"Class average:\" + calculateAverage() + \"\\n\" + \"Maximum mark:\" +  
 calcu         


        
相关标签:
4条回答
  • 2021-01-14 20:46

    You're calling the method calculateAverage this way: calculateAverage(), without any argument. But the method is declared this way:

    private double calculateAverage(double [] marks) 
    

    It thus needs one argument of type double[], but you don't pass anything.

    0 讨论(0)
  • 2021-01-14 20:48

    Look at this:

    String output = "Class average:" + calculateAverage() + ...
    

    What's that meant to be calculating the average of? You've got to provide the method with some data to average. The same is going to be true of calculateMaximum, calculateMinimum etc. Without any context, those methods can't do anything.

    Where are your actual marks stored? Presumably you have some sort of variable storing the marks - so pass that. For example:

    String output = "Class average:" + calculateAverage(actualMarks) + ...
    

    ... except obviously with the real variable, or whatever you're using to store the marks.

    0 讨论(0)
  • 2021-01-14 20:53

    private double calculateAverage(double [] marks) is the method declaration, so when its called it must have and argument of double array

    eg:

    calculateAverage(double_value_array);

    0 讨论(0)
  • 2021-01-14 21:00

    You can call it this way:

    double d[] = {1, 2, 3};
    double ret = calculateAverage(d);
    System.out.println(ret);
    
    0 讨论(0)
提交回复
热议问题