I am trying to read String objects into a 2d array, from a char array, using column-major ordering:
This is what I've tried:
int x = 0;
for (int column = 0; column < matrix[0].length; column++) {//cols
for (int row = 0; row < matrix.length; row++, x++) {//rows
if(matrix[row][column] == null) {
if (x < ciphertextCharacters.length) {
matrix[row][column] = Character.toString(inputChars[x]);
}
}
}
}
given an input array (inputChars = ['t', 't', 'g', 'e', 'i', 's', 'n']) the resulting 2D array should be:
+---+----+----+
| t | e | s |
+---+----+----+
| t | i | n |
+---+----+----+
| g | * | * |
+---+----+----+
Note that before this code runs, the "*" strings are already in the array - and that's why I'm only adding new values when the index is null.
Currently, the resulting 2D array I'm getting is:
+---+----+----+
| t | e | n |
+---+----+----+
| t | i |null|
+---+----+----+
| g | * | * |
+---+----+----+
Which is not what I need.
xtoo often. movex++from the loop declaration to the end of theifblock