该程序可以编译,但是当它写入文件时,会出现以下情况:
[[D@92ca580, [D@52257b34, [D@1abbbd0e, [D@1b78efd8.......
我的代码有什么问题?我的结构是否正确?另外在main方法中调用writefile方法时,我做对了吗?
更新**我修复了它,现在文件中出现了这个:
[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]...
我认为问题在于我没有直接调用 writefile 方法。这是为什么呢?我该如何解决?
import java.io.*;
public class j4 {
public static void main (String [] args) throws IOException
{
int numpoints = 100, dimension = 2, length = 100;//numpoints is set to 100, dimension is set to 2, length is set to 100
//arrays are initializewd and declared
double [] lengthscale = new double [dimension];
double [][] locations = new double [numpoints][dimension];
PrintWriter fileOut = new PrintWriter (new FileWriter ("arrayNumPoints.txt"));
for(int m=0; m <length; m++){//for loop
fileOut.println(java.util.Arrays.toString(locations) + ", ");//writes to file
}
fileOut.close ();//close file
}//end main
public static Double writefile(Double locations[][], Double lengthscale[], int dimension, int numpoints, Double length)throws IOException
{
for (int a = 0; a < dimension; a++){//for loop runs while a is less than dimension
lengthscale[a] = length;//stores array
}//end for loop
for (int x=0; x < numpoints; x++){//for loop runs while x is less than numpoints
for (int y=0; y < dimension; y++){//nested for loop runs while y is less than dimension
locations [x][y]= (2 * Math.random() - 1) * lengthscale[y];//creates the range and choses random point within
return locations[x][y];
}//end nested for loop
}//end for loop
//if program doesnt run through loop.. alternative return statement (but
double b= 1;
return b;
}//end writefile methos
}//end class