java - How to convert 1D array to 2D by column major -


say have 1d array int[] x = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}.
conver 2d looks like:

1 5  9 13   2 6 10 14   3 7 11 15   4 8 12 16   

currently, have

for (int = 0; < 4; i++) {     (int j = 0; j < nb; j++)         s[i][j] = x[i + j]; } 

however, doesnt work. how this?

try

for (int = 0, k=0; < 4; i++)   (int j = 0; j < nb; j++)     s[j][i] = x[k++]; // may want s[i][j] 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -