資料結構-迷宮範例
public class Maze{
public static void main(String[] args){
int maze[][] = {{1,1,1,1,1,1,1},
{1,0,0,0,1,0,1},
{0,0,1,0,1,0,1},
{1,0,1,0,1,0,1},
{1,0,1,1,1,0,1},
{1,0,1,1,1,0,1},
{1,0,0,0,0,0,1},
{1,1,1,1,1,0,1} }; // 宣告迷宮陣列
for (int i = 0; i < 8; i++){
for (int j = 0; j < 7; j++){
if (maze[i][j] == 1) System.out.print('\u2588'); //實心方塊的unicode碼
else System.out.print(" ");//二個空白,配合實心方塊的寬度,剛好是二個空白
}
System.out.println(); //每印完一列跳往下一列
}
System.out.println('\u2190');//左箭頭
System.out.println('\u2191');//上箭頭
System.out.println('\u2192');//右箭頭
System.out.println('\u2193');//下箭頭
}
}
Comments