0
我正在爲我的介紹性Java類指派一個任務,並且遇到了一個我似乎無法弄清楚的錯誤!我必須創建一個靜態的sortIntoGroups
方法來分割數組而不使用任何while循環。該方法必須可以從單獨的驅動程序類中調用。我目前正在嘗試使用主要方法進行測試,但由於某種原因,它似乎無法識別該方法。這裏是我的代碼: 公共類ArrayHelper {找不到符號錯誤:試圖調用方法
public class ArrayHelper{
public static int sortIntoGroups (int[] arrayToSort, int partitionValue){
int i = 0;
int j = (arrayToSort.length-1);
do{
for(i=0; i < partitionValue; i++){
for(j = (arrayToSort.length-1); j > partitionValue; j--){
if (i < j){
int tempVar = arrayToSort[i];
arrayToSort[i] = arrayToSort[j];
arrayToSort[j] = tempVar;
}//end if
}//end j for
}// end i for
}while(i< j);
return j;
}//end sortIntoGroups
public static void main (String [] args){
int [] testArray = {1, 2, 3, 4, 5};
int partitionVal = 4;
System.out.print(testArray.sortIntoGroups(testArray, partitionVal));
}
}
任何想法? 謝謝!
請問你的代碼包含import語句?編譯器還抱怨哪一行?該行中的代碼是什麼? – Ivan