类不能应用于给定类型

时间:2014-04-04 18:03:03

标签: java

我在发表评论的细分时遇到了问题:

  

E:\ School stuff \ Java \ Assign7_Polk.java:60:error:方法ScanArray类中的FindMax无法应用于给定类型;   int highest = findarray.FindMax();   必需:int []     发现:没有争论     原因:实际和正式的参数列表长度不同

我不知道如果给它一个不同的名字还能做什么?

class ScanArray {

    int Max = 0;

    {
    }

    int FindMax(int[] grades) {
        int Max = grades[0];
        for (int i = 1; i < grades.length; i++) {
            if (grades[i] > Max) {
                Max = grades[i];
            }
        }
        return Max;
    }

    int FindMin(int[] grades) {
        int Min = grades[0];
        for (int i = 1; i > grades.length; i++) {
            if (grades[i] < Min) {
                Min = grades[i];
            }
        }
        return Min;

        ScanArray findarray = new ScanArray();

        //Here is the issue!
        int highest = findarray.FindMax();
        int lowest = findarray.FindMin();

        System.out.println("The highest grade is " + highest);
        System.out.println("The lowest grade is " + lowest);
    }
}

1 个答案:

答案 0 :(得分:2)

您没有将数组传递给任何一个函数(使用Java命名约定应该是findMaxfindMin) -

int [] grades = new int[] {1,2,3};
//Here is the issue!
int highest = findarray.FindMax(grades); // <-- pass in some grades.
int lowest = findarray.FindMin(grades);