完成代码的一个简单方法是在已有输出的地方使用字符。
public class Maze {
public static int numRows = 5;
public static int numCols = 5;
public static String[][] maze = new String[numRows][numCols];
// * Method * Creating the maze grid
public static void createMazeGrid(){
// First section of Maze Grid
System.out.print(" ");
for(char alphabet = 'A'; alphabet < 'F'; alphabet++)
System.out.print(alphabet);
System.out.println();
// Middle section of Maze Grid
// *TRY TO FIGURE OUT ALPHABET GRID*
for(int i = 0; i < maze.length; i++) {
System.out.print(" ");
for (int j = 0; j < maze[i].length; j++) {
maze[i][j] = ".";
if (j == 0)
System.out.print((char)('T' - i) + maze[i][j]); // left side
else if (j == maze[i].length - 1)
System.out.print(maze[i][j] + (char)('F' + i)); // right side
else
System.out.print(maze[i][j]);
}
System.out.println();
}
// Last section of Maze Grid
System.out.print(" ");
for(char alphabet = 'O'; alphabet > 'J'; alphabet--)
System.out.print(alphabet);
System.out.println();
}
public static void main(String[] args) { createMazeGrid(); }
}
现在让我们测试一下:
$ java Maze.java
ABCDE
T.....F
S.....G
R.....H
Q.....I
P.....J
ONMLK
看起来不错。:-)