I have been trying to draw a 4x4 grid of squares for about 2 days now and I can't seem to get it down.
Here's the code that I have so far:
StdDraw.setScale(0,4);
int[][] grid = new int [4][4];
for (int x = 0; x < grid.length; x++) {
for (int y = 0; y < grid.length; y++) {
grid[x][y] = 16;
}
}
for (int x = 0; x < grid.length; x++) {
for (int y = 0; y <grid.length; y++) {
StdDraw.square(2.5,3.5,1);
}
}
Unfortunately, it just displays 1 square and I don't know what else to adjust in my code to make the squares as a 4x4 grid. How can I adjust the code accordingly? Any help will be appreciated. I am also using the Dr. Java programming software.
Read more here: https://stackoverflow.com/questions/66483898/how-can-i-draw-a-4x4-grid-of-squares-in-java
Content Attribution
This content was originally published by randall_ingram22 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.