I’m trying to create with java a 7×7 matrix with numbers and letters as indexes to locate each cell. To understand it better, I’m making a field for the naval battle. The problem is that I can’t align the letters with the columns in the array. Do you have any ideas? Of course, the letters are outside the matrix, so it’s a printing problem. I can’t use any kind of GUI.
System.out.print(" A B C D E F G n");
for (int i = 0; i < ROWS; i++) {
System.out.print((i + 1) + " ");
for (int j = 0; j < COLUMNS; j++) {
System.out.print(campo[i][j] + " ");
}
System.out.println(" " + (i + 1));
}
System.out.print(" A B C D E F G n");
I tried to write letters manually with the print function, but they are not aligned to the matrix’s columns.
vinc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.