Java 程序可编译但不';无法正确写入文件

Java 程序可编译但不';无法正确写入文件,java,methods,return,writetofile,Java,Methods,Return,Writetofile,程序进行编译,但当它写入文件时,会出现以下情况: [[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方法。这是为什么吗

程序进行编译,但当它写入文件时,会出现以下情况:

[[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
import java.io.*;
公共类j4{
公共静态void main(字符串[]args)引发IOException
{
int numpoints=100,维度=2,长度=100;//numpoints设置为100,维度设置为2,长度设置为100
//数组被初始化并声明
双[]长度刻度=新双[尺寸];
双精度[][]位置=新的双精度[numpoints][dimension];
PrintWriter fileOut=新的PrintWriter(新的FileWriter(“arrayNumPoints.txt”);
对于(int m=0;m
数组。toString()
仅为第一个数组创建字符串。
位置
是多维数组(数组值包含另一个数组)

您应该尝试:

返回的“深层内容”的字符串表示形式 指定的数组。如果该数组包含其他数组作为元素,则 字符串表示包含其内容等。此方法 用于将多维数组转换为字符串

array.toString()
只为第一个数组创建字符串。
locations
是多维数组(数组值包含另一个数组)

您应该尝试:

返回的“深层内容”的字符串表示形式 指定的数组。如果该数组包含其他数组作为元素,则 字符串表示包含其内容等。此方法 用于将多维数组转换为字符串

试着改用它,这

返回的“深层内容”的字符串表示形式 指定的数组。如果该数组包含其他数组作为元素,则 字符串表示法包含其内容等。此方法 用于将多维数组转换为字符串

但是,假设您不希望以特定的格式打印数字。在这种情况下,您可能需要选择在元素上循环并以所需的格式打印它们

在我看来,上述方法对于日志记录/调试操作非常有用。

请尝试使用,这

返回的“深层内容”的字符串表示形式 指定的数组。如果该数组包含其他数组作为元素,则 字符串表示法包含其内容等。此方法 用于将多维数组转换为字符串

但是,假设您不希望以特定的格式打印数字。在这种情况下,您可能需要选择在元素上循环并以所需的格式打印它们


在我看来,上述方法对于日志记录/调试操作非常有用。

如果您描述了您的程序应该做什么,这将非常有帮助。这就是
#toString()
数组。我想你需要字符串内容,你需要迭代嵌套数组。@qqilihq嗨!你需要字符串内容并迭代嵌套数组是什么意思?我是初学者,所以我有点困惑你有一个2D数组,
数组35; toString
只迭代顶部数组,并简单地给出分辨率因此,每个包含的数组
toString()
的结果(这将为您提供类似
[D@92ca580
如您的示例中所示)。检查下面micha关于
数组的回答。deepToString()
(比我上面建议的迭代更好)@qqilihq好的,谢谢!如果你描述一下你的程序应该做什么,那会有很大帮助。这就是
#toString()
数组。我想你需要字符串内容,你需要迭代嵌套数组。@qqilihq嗨!你需要字符串内容并迭代嵌套数组是什么意思?我是初学者,所以我有点困惑你有一个2D数组,
数组35; toString
只迭代顶部数组,并简单地给出分辨率因此,每个包含的数组
toString()
的结果(这将为您提供类似
[D@92ca580
如您的示例所示)。请检查下面micha关于
数组的回答。deepToString()
(比我上面建议的迭代更好)。@qqilihq好的,谢谢!