This is my toString
method.
public String toString() {
Life game = new Life(grid);
String word;
for (int row = 0; row < grid.length; row++) {
for (int col = 0; col < grid[0].length; col++) {
System.out.print("[" + grid[row][col] + "]");
}
System.out.println();
}
word = "";
return word;
}
I am trying to get the ("[" + grid[row][col] + "]")
; into my String
word. This is to create a game of life grid and I can't figure out how to put the array into a string representation.
Some sample of what it should look like if all the cells were dead. `
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
[0][0][0][0][0][0][0][0][0][0]
When I try word = word + "[" + grid[row][col] + "]"; i get...
[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0]...
All in a straight line.