Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:创建一个对数组排序的方法_Java_Arrays - Fatal编程技术网

Java:创建一个对数组排序的方法

Java:创建一个对数组排序的方法,java,arrays,Java,Arrays,我正在尝试制作一种排序数组的方法 我也制作了数组,但我不确定是否返回并调用它。需要帮忙吗 public void bubbleSort(String words [][] ) { for (byte count1 = 0; count1 < words.length - 1; count1++) for (byte count2 = 0; count2 < ((words.length)-count1); count2++) {

我正在尝试制作一种排序数组的方法 我也制作了数组,但我不确定是否返回并调用它。需要帮忙吗

public void bubbleSort(String words [][] ) {

        for (byte count1 = 0; count1 < words.length - 1; count1++) 
            for (byte count2 = 0; count2 < ((words.length)-count1); count2++) {
            System.out.print(words[count1][count2] + " ");

            Arrays.sort(words); 

        }
        return words [count1][count2];
    }

不需要将数组返回给main函数,因为数组内容的更改反映在main中函数调用期间传递的数组中。在主功能中,执行以下操作:

初始化二维字符串,如:

String[][] rows = new String[10][10];
将所需的数组放入其中

然后调用函数作为

bubbleSort(rows);

行数组包含已排序的字符串

你为什么要退货?对数组排序会更改内容;通常没有返回值,除了一个布尔值,它指示是否实际发生了任何更改。无论如何,由于您的方法被声明为void,因此无法返回值。这是一段相当奇怪的代码。你到底想要实现什么?除此之外:返回类型为void的方法不返回任何内容。只需保留return语句,如果您正在处理传入的数组字,则不需要返回它-您已将方法声明为return类型void,因此只需删除return语句即可。说到这里,您正在为每个元素调用整个数组的array.sort。。。您可能需要在那里检查您的逻辑。