下面是主要方法:传递数组回主方法
public static void main(String[] args) throws IOException{
int [] array = new int [1000];
int[] getArray=FileArrayProvider(array);
for (int y = 0; y < getArray.length; ++y)
{
System.out.print(array[y] + " ");
}
我想通过“数组”到方法“FileArrayProvider下面:
public static int[] FileArrayProvider(int[] array1) throws IOException{
File file = new File("RandomNumbers.txt");
FileReader inputFile = new FileReader(file);
BufferedReader in = new BufferedReader(inputFile);
{String s =in.readLine();
System.out.println("Array before sorting: ");
while(s!=null)
{int k = 0;
array1[k] = Integer.parseInt(s);
System.out.print(array1[k]+" ");
s = in.readLine();
}
in.close();
}
return array1;
}
的问题是,该数组不被传递回主方法。它正在'FileArrayprovider'方法内正确打印,但仅将数组的最后一个值传递回主方法,并将所有零填充到数组中。任何提示或建议,将不胜感激,以解决这个问题!谢谢
没有必要返回'array1',因为它与参数相同,并且您从不分配给它。 – newacct