有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

类中的java不能使输入数组等于另一个数组

我有一段代码,它将字符串转换成整数,对它进行快速排序,然后将这些整数转换成字符串。代码工作没有问题,但我想尝试将字符串的整数放入与它们的was相同的输入数组中,而不是生成整个其他数组,这不起作用,因为它甚至没有更改输入。因此,我让int-to-string数组方法在一个新数组中返回给我,调试时,这正是我想要的。然后我做了,这样输入数组等于我放入的新数组,现在返回的是一堆乱七八糟的字母

public class runner
{
    static void singleletterarrayalphabeticalorganizer(String[] a)
    {

   int[] number = stoianditos.singlestoi(a);//makes the string into an integer
    quicksort.sort(number,0,a.length-1);//quicksorts the integers
    String[] a1 = stoianditos.singleitos(number);//makes the integers into strings
    // i tried to put a intead of a1 but it gave me the same result
    a = a1;
    //PROBLEM AREA: suppoused to make the input given the same as a1 so i dont have to make a new array in the main class(if thats where im running it) instead of using the already exsisting array
}
}

共 (2) 个答案

  1. # 1 楼答案

    对于整数t字符串的转换器,我将使它也接受一个int数组,而不是返回一个新数组,我将使它只更改字符串数组

  2. # 2 楼答案

    不能更改传入方法的参数。如果要传回已排序的字符串数组,请将方法的返回类型更改为“String[]”,而不是“void”,然后执行“return a1;”