multidimensional array - Referring to variable in Java? -


i have 3d array called em:

double[][][] em = new double[4][4][4]; 

i have helper method converts intto char:

public static char inttochar(int i) {     switch (i) {     case 0:         return 'a';     case 1:         return 'b';     case 2:         return 'c';     default:         return 'd';     } } 

i have 4 integer variables:

int = 108; int b = 299; int c = 302; int d = 411; 

now, here tricky part. want go through each index of 3d array em , multiply index values. [0][0][0] = 1*1*1 = 1; [0][0][1] = 1*1*2 = 2; ...; [3][3][3] = 4*4*4 = 64.

for (int i=0; i<4; i++){     (int j=0; j<4; j++){         (int k=0; k<4; k++){             char = inttochar(i);             char j = inttochar(j);             char k = inttochar(k);             // not sure here         }     } } 

how can that?

you need able refer a...d index, need index them in array:

int[] d = {a, b, c, d}; 

which goes before loop. loop easy:

em[i][j][k] = d[i]*d[j]*d[k]; 

this set each of values @ (i,j,k) corresponding a...d multiplicands.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -