gpt4 book ai didi

java - Lejos 在初始化矩阵时给出错误

转载 作者:行者123 更新时间:2023-11-30 10:53:01 26 4
gpt4 key购买 nike

我们正在尝试构建一个机器人,为了让机器人了解他现在的位置,我们将使用矩阵。

所以我要调出矩阵。没有任何来自 main.java 的东西。然后尝试使用 initMatrix,它只是给我一个错误。

public class Matrix {

// Matrix creation
public String[][] maturix = new String[10][10];
// Recorded Position of the Robot
public int x=0;
public int y=10;
public int Ox;
public int Oy;
public String Orientation = "East"; //Initializing the robot East-oriented to help place Obstacles (either Walls or Sheep) and walking

public void initMatrix()
{
// Summary: E = Empty; G = Sheep; W = Wall; C = current position; F = Finishing Line; X = Null; U = Unknown


maturix[10][0] = "S"; //Starting Position
maturix[10][1] = "U";
maturix[10][2] = "U";
maturix[10][3] = "U";
maturix[10][4] = "U";
maturix[10][5] = "U";
maturix[10][6] = "U";
maturix[10][7] = "U";
maturix[10][8]= "U";
maturix[10][9] = "U";
maturix[10][10] = "U";
maturix[9][1] = "X";
maturix[9][2] = "U";
maturix[9][3] = "X";
maturix[9][4] = "U";
maturix[9][5] = "X";
maturix[9][6] = "U";
maturix[9][7] = "X";
maturix[9][8] = "U";
maturix[9][9] = "X";
maturix[9][10] = "U";
maturix[8][0] = "U";
maturix[8][1] = "U";
maturix[8][2] = "U";
maturix[8][3] = "U";
maturix[8][4] = "U";
maturix[8][5] = "U";
maturix[8][6] = "U";
maturix[8][7] = "U";
maturix[8][8] = "U";
maturix[8][9] = "U";
maturix[8][10] = "U";
maturix[7][0] = "U";
maturix[7][1] = "X";
maturix[7][2] = "U";
maturix[7][3] = "X";
maturix[7][4] = "U";
maturix[7][5] = "X";
maturix[7][6] = "U";
maturix[7][7] = "X";
maturix[7][8] = "U";
maturix[7][9] = "X";
maturix[7][10] = "U";
maturix[6][0] = "U";
maturix[6][1] = "U";
maturix[6][2] = "U";
maturix[6][3] = "U";
maturix[6][4] = "U";
maturix[6][5] = "U";
maturix[6][6] = "U";
maturix[6][7] = "U";
maturix[6][8] = "U";
maturix[6][9] = "U";
maturix[6][10] = "U";
maturix[5][0] = "U";
maturix[5][1] = "X";
maturix[5][2] = "U";
maturix[5][3] = "X";
maturix[5][4] = "U";
maturix[5][5] = "X";
maturix[5][6] = "U";
maturix[5][7] = "X";
maturix[5][8] = "U";
maturix[5][9] = "X";
maturix[5][10] = "U";
maturix[4][0] = "U";
maturix[4][1] = "U";
maturix[4][2] = "U";
maturix[4][3] = "U";
maturix[4][4] = "U";
maturix[4][5] = "U";
maturix[4][6] = "U";
maturix[4][7] = "U";
maturix[4][8] = "U";
maturix[4][9] = "U";
maturix[4][10] = "U";
maturix[3][0] = "U";
maturix[3][1] = "X";
maturix[3][2] = "U";
maturix[3][3] = "X";
maturix[3][4] = "U";
maturix[3][5] = "X";
maturix[3][6] = "U";
maturix[3][7] = "X";
maturix[3][8] = "U";
maturix[3][9] = "X";
maturix[3][10] = "U";
maturix[2][0] = "U";
maturix[2][1] = "U";
maturix[2][2] = "U";
maturix[2][4] = "U";
maturix[2][5] = "U";
maturix[2][6] = "U";
maturix[2][7] = "U";
maturix[2][8] = "U";
maturix[2][9] = "U";
maturix[2][10] = "U";
maturix[1][0] = "U";
maturix[1][1] = "X";
maturix[1][2] = "U";
maturix[1][3] = "X";
maturix[1][4] = "U";
maturix[1][5] = "X";
maturix[1][6] = "U";
maturix[1][7] = "X";
maturix[1][8] = "U";
maturix[1][9] = "X";
maturix[1][10] = "U";
maturix[0][0] = "U";
maturix[0][1] = "U";
maturix[0][2] = "U";
maturix[0][3] = "U";
maturix[0][4] = "U";
maturix[0][5] = "U";
maturix[0][6] = "U";
maturix[0][7] = "U";
maturix[0][8] = "U";
maturix[0][9] = "U";
maturix[0][10] = "5";

}
}

有什么想法吗?

最佳答案

java 中的数组索引是从 0 开始的。

因此,如果您键入 maturix[10][0],您将访问第 11 个元素。在声明中加 1,public String[][] maturix = new String[11][11];

关于java - Lejos 在初始化矩阵时给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34157567/

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