I am trying to create a grid String matrix using a 2D array. The matrix should be mxm
, this will vary on the user's input. The first column must consist of .
and the columns thereafter must consist of *
. I have imported the java.util.Arrays
method and am using the toString
function. The problem is that I am getting an output that has delimiters as well as prefixes and suffixes. The output looks like this:
[., *, *, *, *, *, *, *]
[., *, *, *, *, *, *, *]
[., *, *, *, *, *, *, *]
[., *, *, *, *, *, *, *]
[., *, *, *, *, *, *, *]
[., *, *, *, *, *, *, *]
[., *, *, *, *, *, *, *]
[., *, *, *, *, *, *, *]
However, I want the code to look like this:
.*******
.*******
.*******
.*******
.*******
.*******
.*******
.*******
So essentially I want to know if there is a way to get the matrix to have no square brackets or commas and how would I go about achieving this?
import java.util.Arrays;
public class trial1 {
public static void main(String[] args) {
StdOut.println("What size matrix would you like?");
int m = StdIn.readInt();
// create board
String[][] gameBoard = new String[m][m];
for(int i = 0; i < gameBoard.length; i++) {
Arrays.fill(gameBoard[i], "*");
gameBoard[i][0] = ".";
StdOut.println(Arrays.toString(gameBoard[i]));
}
}
}