12.在三維陣列中找出最小值
array[][][] = {{{15, 85, 36}, {30, 14, 37},
{47, 23, 96}, {19, 39, 51}},
{{22, 16, 51}, {97, 30, 12},
{68, 77, 26}, {57, 32, 76}}};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | int a = Integer.MAX_VALUE; int b = 0; int c = 0; int d = 0; int array[][][] = {{{15, 85, 36}, {30, 14, 37}, {47, 23, 96}, {19, 39, 51}}, {{22, 16, 51}, {97, 30, 12}, {68, 77, 26}, {57, 32, 76}}}; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { for (int k = 0; k < array[i][j].length; k++) { if (array[i][j][k] < a) { a = array[i][j][k]; b = i; c = j; d = k; } } } } System.out.println("此三維陣列最小值為array[" + b + "][" + c + "][" + d + "]="+a); |
沒有留言:
張貼留言