0
我无法弄清楚如何将一个二维数组放入另一个二维数组中。在另一个二维数组中放置一个二维数组java
public class MazeAnalyze{
public static void main(String[]args){
Scanner kbd = new Scanner(System.in);
String str = "";
System.out.println("Enter dimensions");
int n = kbd.nextInt();
char [][] mazeValue = new char[n][n];
char[][] newMaze = new char[n+2][n+2];
String [] input= new String [n];
int [][] totalOpen = new int [n][n];
char X= 88;
System.out.println("Enter the maze");
for(int i =0; i <input.length; i++){
input[i] = kbd.next().toUpperCase();
}
for(int x=0; x< input.length;x++){
mazeValue[x]= input[x].toCharArray();
}
System.out.println("The maze array contains:");
for(int i=0; i<mazeValue.length; i++){
for(int j=0; j<mazeValue[i].length;j++){
System.out.print(mazeValue[i][j]);
}//end of second loop
System.out.println();
}//end of first loop
System.out.println("The maze with the Xs are");
for(int i=0; i<newMaze.length; i++){
for(int j=0; j<newMaze[i].length;j++){
newMaze[i][j]= 'X';
}//end of second loop
}//end of first loop
for(int i=0; i<newMaze.length; i++){
for(int j=0; j<newMaze[i].length;j++){
System.out.print(newMaze[i][j]);
}
System.out.println();
}
for(int x=0; x<n-2; x++){
for(int i=0; i<mazeValue.length; i++){
for(int j=0; j<mazeValue[i].length;j++){
newMaze[i+1][j+1]= mazeValue[i][j];
}
}
}//end of main for loop
这是我的输出:
输入尺寸输入迷宫
XOX
白叶枯病
OOO
迷宫数组包含:
XOX
XOO
OOO
与两个X迷宫是
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
与边框的迷宫
XOX
XOO
OOO
我要的是:
我的迷宫阵包围X就像一个边框。有什么建议么?
有反正我可以使用循环吗? – user3546001 2015-02-24 15:56:34