I have to populate a 2D array and print the result | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I have to populate a 2D array and print the result

I have the following function: the purpose is to have the 1st column as serial number 0 through 63, rest of the columns will start with 63, 62, 56. But once the value is 63, the next value would be 0 and then it will keep increasing by 1. so the 2nd row will have 0, 63, 57. 3rd row will have 1, 0, 58 and so on.. public void lookup_table(int x) { int i = 64, j= 4 , a, b; int arr_lookup [][] = new int [i][j]; for (a = 0; a < 64; a++){ arr_lookup[a][0] = a ; if (a == 0) { arr_lookup[a][1] = 63; arr_lookup [a][2] = 62; arr_lookup [a] [3] = 56; } else { if (arr_lookup [a-1][1]== 63 ) arr_lookup[a][1] = 0; else arr_lookup [a][1] = arr_lookup [a-1][1] + 1; if (arr_lookup [a-1][2]== 63 ) arr_lookup[a][2] = 0; else arr_lookup [a][2] = arr_lookup [a-1][2] +1; if (arr_lookup [a-1][3]== 63 ) arr_lookup[a][3] = 0; else arr_lookup [a][3] = arr_lookup [a-1][3] +1; } } System.out.println(arr_lookup[a][0]+'-'+arr_lookup[a][1]+'-'+arr_lookup[a][2]+'-'+arr_lookup[a][3]); }

4th Dec 2016, 7:23 AM
Moitrayee
1 Answer
+ 1
To populate the array, you could have a for loop for each dimension that populates it To print the result, you'd have to do System.out.println(Arrays.toString(arr_lookup));
6th Dec 2016, 2:30 AM
Nikhil Kolachalama
Nikhil Kolachalama - avatar