Java 打印具有3D数组字段的类

Java 打印具有3D数组字段的类,java,arrays,class,Java,Arrays,Class,我有一门课是: public class CCTest { public double f; public double[][][] x; public double counter; }; 我给x分配了一个随机数 CCTest[] cls = new CCTest[5]; for (int i = 0; i < cls.length; i++) { cls[i] = new CCTest(); } for (int i = 0; i <

我有一门课是:

 public class CCTest {
 public double f;
 public double[][][] x;
 public double counter;
 };
我给x分配了一个随机数

    CCTest[] cls = new CCTest[5];
    for (int i = 0; i < cls.length; i++) {
    cls[i] = new CCTest();
  }

   for (int i = 0; i < (Size = 5); i++) {
   cls[i].x = new double[this.c][this.D][this.Size];
   for (int j = 0; j < this.D; j++) {
    cls[i].x = getRandomX(this.c, this.D, this.Size);
  }
 }
CCTest[]cls=新的CCTest[5];
对于(int i=0;i
然后,我尝试使用以下方法显示结果:

   public static void display(double[][][] array) {

    int rows = array.length;
    int columns = array[0].length;
    int depth = array[0][0].length;

    for (int d = 0; d < depth; d++) {
        for (int r = 0; r < rows; r++) {
            for (int c = 0; c < columns; c++) {
                System.out.print(array[r][c][d] + " ");
            }
          System.out.println();
        }

        System.out.println();
    }
} 
公共静态无效显示(双[]阵列){
int rows=array.length;
int columns=数组[0]。长度;
int depth=数组[0][0]。长度;
对于(int d=0;d
随机生成方法为:

      public static double[][][] getRandomX(int x, int y, int z) {
      double[][][] result = new double[x][y][z];
      Random r = new Random();

    for (int i = 0; i < z; i++) {
        for (int j = 0; j < y; j++) {
            for (int k = 0; k < x; k++) {
                result[k][j][i] = r.nextDouble();
            }
        }
    }
    return result;
}
publicstaticdouble[][]getRandomX(intx,inty,intz){
双精度[][]结果=新的双精度[x][y][z];
随机r=新随机();
对于(int i=0;i

但是输出是空的[],有什么想法请

您的
显示
方法应该如下所示:

public static void display(double[][][] array) {
    for (int x = 0; x < array.length; x++) {
        for (int y = 0; y < array[x].length; y++) {
            for (int z = 0; z < array[x][y].length; z++) {
                System.out.println(array[x][y][z]);
            }
        }
    }
}
公共静态无效显示(双[]阵列){
对于(int x=0;x
我脑子里还有一个问题。什么是getRandomX?你还没有给我们看。我会使用以下方法:

public static double[][][] getRandom3DArray(double[][][] array) {

    Random r = new Random();
    for (int x = 0; x < array.length; x++) {
        for (int y = 0; y < array[x].length; y++) {
            for (int z = 0; z < array[x][y].length; z++) {
                array[x][y][z] = r.nextDouble();
            }
        }
    }
    return array;
}
公共静态双[][]getRandom3DArray(双[][]array){
随机r=新随机();
对于(int x=0;x

您将显示器中的
深度
弄错了。

您的
显示
方法应该类似于:

public static void display(double[][][] array) {
    for (int x = 0; x < array.length; x++) {
        for (int y = 0; y < array[x].length; y++) {
            for (int z = 0; z < array[x][y].length; z++) {
                System.out.println(array[x][y][z]);
            }
        }
    }
}
公共静态无效显示(双[]阵列){
对于(int x=0;x
我脑子里还有一个问题。什么是getRandomX?你还没有给我们看。我会使用以下方法:

public static double[][][] getRandom3DArray(double[][][] array) {

    Random r = new Random();
    for (int x = 0; x < array.length; x++) {
        for (int y = 0; y < array[x].length; y++) {
            for (int z = 0; z < array[x][y].length; z++) {
                array[x][y][z] = r.nextDouble();
            }
        }
    }
    return array;
}
公共静态双[][]getRandom3DArray(双[][]array){
随机r=新随机();
对于(int x=0;x
您将显示器中的
深度
弄错了。

内部循环:for(int j=0;j
    CCTest[] cls = new CCTest[5];
    for (int i = 0; i < cls.length; i++) {
        cls[i] = new CCTest();
    }

    for (int i = 0; i < (Size = 5); i++) {
        cls[i].x = new double[c][D][S];
        cls[i].x = getRandomX(c, D, S);
    }
    for (int i = 0; i < (Size = 5); i++) {
        display(cls[0].x);
    }
CCTest[]cls=新的CCTest[5];
对于(int i=0;i
内部循环:for(int j=0;j
    CCTest[] cls = new CCTest[5];
    for (int i = 0; i < cls.length; i++) {
        cls[i] = new CCTest();
    }

    for (int i = 0; i < (Size = 5); i++) {
        cls[i].x = new double[c][D][S];
        cls[i].x = getRandomX(c, D, S);
    }
    for (int i = 0; i < (Size = 5); i++) {
        display(cls[0].x);
    }
CCTest[]cls=新的CCTest[5];
对于(int i=0;i
this.c、this.D、this.Size@Thusitha:this.c=2的值是多少;例如,这个.D=2;This.size=10您是否可以在getRandomX()中显示代码作为其初始化数组的内容This.c、This.D、This.size@Thusitha:This.c=2的值;例如,这个.D=2;This.size=10是否可以在getRandomX()中显示代码作为初始化array@Nyakiba它有很大不同,因为它提供了正确的
getRandom3DArray
函数。他在那里有一个错误。@Xentros我添加了随机生成方法,iam将参数添加到该方法:
cls[i].x=getRandomX(this.c,this.D,this.Size),它们是changing@Nyakiba它有很大不同,因为它提供了正确的
getRandom3DArray
函数。他在那里有一个错误。@Xentros我添加了随机生成方法,iam将参数添加到该方法:
cls[i].x=getRandomX(this.c,this.D,this.Size),它们正在更改