2014-04-04 58 views
-2

我有註釋的部分它散發出此錯誤的問題:類不能被應用到給定類型

E:\School stuff\Java\Assign7_Polk.java:60: error: method FindMax in class ScanArray cannot be applied to given types; int highest = findarray.FindMax(); required: int[] found: no arguments reason: actual and formal argument lists differ in length

我不知道做什麼別的它應該被賦予不同的名稱?

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); 
    } 
} 
+3

你調用'findarray.FindMax()'。你的FindMax方法期望什麼?基本上,它應該在哪裏尋找最大值? –

+0

如何嘗試查找進入代碼的最小值和最大值的數組?這是詢問用戶值的程序的一部分嗎?更重要的是,該數組實際上是'ScanArray'類的成員?無論是否會影響解決此錯誤的最佳方法。 –

回答

2

你是不是傳遞一個數組要麼你的函數(這應該是findMaxfindMin與Java命名約定) -

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); 
相關問題