0

入門 Java クラスの課題に取り組んでいるときに、理解できないエラーが発生しました。sortIntoGroupswhile ループを使用せずに配列を分割する静的メソッドを作成する必要があります。メソッドは、別のドライバー クラスから呼び出せる必要があります。現在、main メソッドでテストしようとしていますが、何らかの理由でメソッドを認識していないようです。これが私のコードです: public class 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));

}
}   

何か案は?ありがとう!

4

1 に答える 1

0

静的メソッドはクラス名で参照されます。メソッドを次のように呼び出す必要があります

   System.out.print(ArrayHelper.sortIntoGroups(testArray, partitionVal));

それが役立つことを願っています:)

于 2016-11-22T19:59:25.190 に答える