【发布时间】:2017-02-14 21:11:42
【问题描述】:
我有一门课是:
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);
}
}
然后我尝试使用显示结果:
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();
}
}
随机生成方法是:
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;
}
但输出为空 [] ,请提供任何想法
【问题讨论】:
-
this.c、this.D、this.Size的值是多少
-
@Thusitha : this.c=2; this.D=2,例如 ; this.size=10
-
能否请您将 getRandomX() 中的代码显示为初始化数组的内容