如何制作棋盘格?
0代表白色,1代表黑色
我一开始把它们都设为 0,然后尝试添加 1,但它给了我
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at unit1.Lesson35CheckerboardTask.main(Lesson35CheckerboardTask.java:33)
public static void main(String[] args){
int a[][] = new int [8][8];
for (int test = 0; test < a.length; test++)
{
int row = 0;
int col = 0;
for (int col1 =0; col1 < 8;col1++)
{
a[row][col] = 1;
col = col + 2;
}
row = row + 1;
col = (col - 6);
}
//(this prints it out)
for (int row = 0; row < a.length; row++)
{
for(int col = 0; col <a[row].length; col++)
{
System.out.print(a[row][col] + "\t");
}
System.out.println("");
}
}
}