java三维数组
java三维数组代码如下:packageArrayDemo;publicclassArrayDemo{publicstaticvoidmain(String[]args)...
java三维数组代码如下:
package ArrayDemo;
public class ArrayDemo {
public static void main(String[] args) {
int i, j, k,sum;
int a[][][] = { { { 1, 2, 3 }, { 4, 5, 6 } },
{ { 7, 8, 9 }, { 10, 11, 12 } } };
for (i = 0; i <a.length; i++) {
for (j = 0; j < a[i].length; j++) {
for (k = 0; k < a[j].length; k++) {
System.out.println("a[" + i + "] [" + j + "] [" + k
+ "] = " + a[i][j][k]);
}
}
}
}
}
系统输出:
a[0] [0] [0] = 1
a[0] [0] [1] = 2
a[0] [1] [0] = 4
a[0] [1] [1] = 5
a[1] [0] [0] = 7
a[1] [0] [1] = 8
a[1] [1] [0] = 10
a[1] [1] [1] = 11
求解:为什么不能输出全部的数组元素?? 展开
package ArrayDemo;
public class ArrayDemo {
public static void main(String[] args) {
int i, j, k,sum;
int a[][][] = { { { 1, 2, 3 }, { 4, 5, 6 } },
{ { 7, 8, 9 }, { 10, 11, 12 } } };
for (i = 0; i <a.length; i++) {
for (j = 0; j < a[i].length; j++) {
for (k = 0; k < a[j].length; k++) {
System.out.println("a[" + i + "] [" + j + "] [" + k
+ "] = " + a[i][j][k]);
}
}
}
}
}
系统输出:
a[0] [0] [0] = 1
a[0] [0] [1] = 2
a[0] [1] [0] = 4
a[0] [1] [1] = 5
a[1] [0] [0] = 7
a[1] [0] [1] = 8
a[1] [1] [0] = 10
a[1] [1] [1] = 11
求解:为什么不能输出全部的数组元素?? 展开
4个回答
展开全部
public class ArrayDemo {
public static void main(String[] args) {
int i, j, k,sum;
int a[][][] = { { { 1, 2, 3 }, { 4, 5, 6 } },
{ { 7, 8, 9 }, { 10, 11, 12 } } };
for (i = 0; i <a.length; i++) {
for (j = 0; j < a[i].length; j++) {
for (k = 0; k < a[i][j].length; k++) {//这儿
System.out.println("a[" + i + "] [" + j + "] [" + k
+ "] = " + a[i][j][k]);
}
}
}
}
}
展开全部
for (i = 0; i <a.length; i++) {
for (j = 0; j < a[i].length; j++) {
for (k = 0; k < a[i][j].length; k++) {
System.out.println("a[" + i + "] [" + j + "] [" + k
+ "] = " + a[i][j][k]);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
k < a[i][j].length
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询