I'm trying to create the game 2048 but a little different. Instead of displaying a grid that is usually 4x4, I want to display the grid based on what the user would like. For example, if the user enters the number 6, the game board should be 6x6. The code I have here is for displaying a grid 4x4, but I'm stuck on trying to figure out how to display any grid. I have been stuck on this for hours.
How do I fix this to display the game board based on the user's input?
String rowDashes = "----------------";
for ( int i = 0; i < board.length; i++) {
System.out.println(rowDashes);
System.out.print("|");
for (int j =0; j < board[i].length;j++) {
String number = "";
if (board[i][j] != 0)
{
number = board[i][j] + "";
}
System.out.print(" " + number + "|");
}
System.out.println();
}
System.out.println(rowDashes);