所以基本上我正在尝试编写一个寻路程序,该程序可以找到从 10*10 网格中的某个点到另一个点的路径,这很好。
我有一个类Path
,它是 s 的 ArrayList GridSquare
(它们只是美化的坐标)。
我在Path
类中编写了一个小方法来显示路径,这就是问题的出现,这个问题非常小但非常令人恼火。
当我尝试运行代码并调用displayPath
时,没有任何内容输出到控制台,并且程序终止且没有错误。
这是代码displayPath
:
public void displayPath(){
System.out.println("This is displayPrint"); //This line is included to make sure the program calls the method correctly.
for(int i=1; i==10; i++){
for(int j=1; j==10; j++){
if(this.includesSquare(i, j)){
System.out.print("[x]");
} else {
System.out.print("[ ]");
}
}
System.out.print("\n");
}
}
我包括第一行以确保 console/System.out.print() 正常工作,并且每次调用该方法时都会显示。
这是代码includesSquare
:
public boolean includesSquare(int x, int y){
for(GridSquare square : this.path){
if(square.getX()==x && square.getY()==y){
return true;
}
}
return false;
}
我已经卸载并重新安装了 Eclipse,将 java 文件复制到一个新项目等中,似乎没有任何区别。我知道控制台工作正常,因为它正确显示了第一行displayPath
。
任何帮助是极大的赞赏!