I was trying to reproduce a code from the book I am reading and can't get to make it work. Here is the code:
public class ThreeDArray {
public static void main(String[] args) {
int threeD [][][] = new int [3][4][5];
int i, j, k;
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 5; k++) {
threeD [i][j][k] = i*j*k;
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 5; k++) {
System.out.print(threeD[i][j][k]+" ");
}
System.out.println("");
}
System.out.println("");
}
}
}
}
I am getting this output:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
I am getting all zeros here and I can't find the mistake here. Please advise what is wrong here.