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));

}
}   

有任何想法吗?谢谢!

4

1 回答 1

0

静态方法由类名引用。您应该将该方法称为

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

希望有帮助:)

于 2016-11-22T19:59:25.190 回答