gpt4 book ai didi

java - 这个二维数组有什么问题?

转载 作者:行者123 更新时间:2023-11-29 09:50:05 25 4
gpt4 key购买 nike

我在 Java 中使用二维数组,这是第一次这样做。我想知道数组出了什么问题,因为我遇到了很多错误......? (可能是一个非常愚蠢的错误)

代码

    int board[21][21] = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 
{1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1},
{1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1},
{1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},
{1,0,1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,1,0,1},
{1,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,1},
{1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,1,1,1},
{0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0},
{1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1},
{0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0},
{1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,1,1,1},
{1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,1},
{1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1},
{1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1},
{1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1},
{1,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,0,1},
{1,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,1},
{1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}};

错误列表 Here is a link instead of posting it here since it's a lot of errors

最佳答案

您不能在声明中指定数组的大小。如果您删除大小整数,它将编译。但是,当您这样声明变量时,您应该始终将括号放在变量的类型上,而不是放在变量本身上:

int[][] board;

而不是:

int board[][];

如果您想创建一个具有特定大小的空白数组,那么您可以使用 new 运算符:

int[][] board = new int[21][21];

但是,如果您通过数组初始化定义数组,则永远不会指定大小

int[][] board = {{...}, ...};

关于java - 这个二维数组有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8141804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com