日期:2014-05-20 浏览次数:20809 次
public static void main(String[] args) { int [][][][][][][] ar={{{{{{ {40,10,41,21}, {25,14,10}, {11,44,4,25,63}, {54,354,71,4}, {65}, {6,365,41,255,11,47}, {57,857,7,7478,540,1} }}}}}}; int g=( ar[0][0][0][0][0][0].length+ ar[0][0][0][0][0][1].length+ ar[0][0][0][0][0][2].length+ ar[0][0][0][0][0][3].length+ ar[0][0][0][0][0][4].length+ ar[0][0][0][0][0][5].length+ ar[0][0][0][0][0][6].length); System.out.println("数组中总元素个数为 "+g); for(int i=0;i<ar.length;i++) { for(int a=0;a<ar[i].length;a++) { for(int b=0;b<ar[i][a].length;b++) { for(int c=0;c<ar[i][a][b].length;c++) { for(int d=0;d<ar[i][a][b][c].length;d++) { for(int e=0;e<ar[i][a][b][c][d].length;e++) { for(int f=0;f<ar[i][a][b][c][d][e].length;f++) { System.out.println(ar[i][a][b][c][d][e][f]); } } } } } } } }
int [][][][][][][] ar={{{{{{ {40,10,41,21}, {25,14,10}, {11,44,4,25,63}, {54,354,71,4}, {65}, {6,365,41,255,11,47}, {57,857,7,7478,540,1} }}}}}}; int g = 0; for (int[] i : ar[0][0][0][0][0]) { for (int j : i) { g++; System.out.println(j); } } System.out.println("=================== "); System.out.println("数组中总元素个数为 "+g);
------解决方案--------------------
public class text3 { public static void main(String[] args) { { int[][][][][][][] ar = { { { { { { { 40, 10, 41, 21 }, { 25, 14, 10 }, { 11, 44, 4, 25, 63 }, { 54, 354, 71, 4 }, { 65 }, { 6, 365, 41, 255, 11, 47 }, { 57, 857, 7, 7478, 540, 1 } } } } } } }; int g = (ar[0][0][0][0][0][0].length + ar[0][0][0][0][0][1].length + ar[0][0][0][0][0][2].length + ar[0][0][0][0][0][3].length + ar[0][0][0][0][0][4].length + ar[0][0][0][0][0][5].length + ar[0][0][0][0][0][6].length); System.out.println("数组中总元素个数为 " + g); int o = g; for (int i = 0; i < ar.length; i++) { for (int a = 0; a < ar[i].length; a++) { for (int b = 0; b < ar[i][a].length; b++) { for (int c = 0; c < ar[i][a][b].length; c++) { for (int d = 0; d < ar[i][a][b][c].length; d++) { for (int e = 0; e < ar[i][a][b][c][d].length; e++) { for (int f = 0; f < ar[i][a][b][c][d][e].length; f++) { g--; System.out.println("第" + (o - g) + "个元素为:" + ar[i][a][b][c][d][e][f]); } } } } } } } } } }