public static Shape [] sortShapes(Shape [] shapes) {
    int min;
    for (int i = 0; i < shapes.length; i++) {
        // Assume first element is min

        min = i;
        for (int j = i + 1; j < shapes.length; j++) {
            if (shapes[i].compareTo(shapes[j]) == -1) {
                 Shape temp = shapes[i];
                shapes[min] = shapes[i];
                shapes[i] = temp;

            }
        }


    }
    return shapes;
}


我正在尝试编写一种方法,该方法将对形状进行排序并返回已排序的数组
但是输出没有给我任何东西,没有输出

最佳答案

尝试替换这些:

    int temp = shapes[i] ; **
    ...
    shapes[i] =  temp[i] ;


带有:

   Shape temp = shapes[i] ;
   ...
   shapes[i] =  temp ;


因为temp是Shape对象。

关于java - 排序形状方法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35445707/

10-10 04:36