我正在尝试打印棋盘网格,但它只打印 A 文件,然后只打印出 7 个空行。
这是我的代码:
public class Board
{
public static void main(String[] args)
{
char rows = 'a';
int col = 0;
String spot;
int[][] grid = new int [8][8];
for(int i = 0; i <= grid.length; i++, rows++)
{
for(; col < grid.length; col++)
{
System.out.print(rows + "" + (col + 1) + " ");
}
System.out.println();
}
}
}
我确信这是显而易见的事情,但我无法弄清楚。我需要更改什么才能打印完整的棋盘网格?
最佳答案
使用增强的 for 循环来实现:
for(int[] row : grid){
for(int square : row){
System.out.print(square + " ");
}
System.out.println();
}
关于java - 在java中打印棋盘网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55309533/