好的,所以我有一个“无法入睡,不妨编程”的夜晚。截至目前,我可能只是过度疲劳,但是,它困扰着我。我试图让我的代码将 char[] 选项打印到 8x8 数组中。我设置了我的方法,但它最终打印到另一个 8 x 8 阵列,直接位于我的另一个 8 x 8 阵列下方。警告这可能是一个极端愚蠢的错误。但是,我现在似乎忘记了我所有的错误。任何帮助将不胜感激!谢谢!
'
static char[] options = {'*','$','@','+','!','&'};
public static void main(String[] args){
System.out.println("How to play: type a row and column index, followed by \n" +
"the direction to move it: u (up), r (right), d (down), l (left)");
char[][] grid = new char[8][8];
drawGrid(grid);
populateRandom(grid,options);
System.out.println("Enter <row> <column> <direction to move> or q to quit");
//char randomChar = 66;
//System.out.println(randomChar);
}
public static void drawGrid(char[][] grid){
System.out.println("\t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8");
System.out.println();
//Random r = new Random();
for(int row=0 ; row < grid.length ; row++) {
//populateRandom(grid,options);
System.out.print((row+1)+"");
for(int column=0 ; column < grid[row].length ; column++){
//populateRandom(grid, options);
}
System.out.println();
}
System.out.println();
}
public static void populateRandom(char[][] grid, char[] options)
{
Random randomGenerator = new Random();
for (int row = 0; row < grid.length; row++){
for (int column=0; column < grid[row].length; column++){
int randomIndex = randomGenerator.nextInt(6);
grid[row][column] = options[randomIndex];
System.out.print("\t" + grid[row][column]);
}
System.out.println();
}
}
public static boolean isWithinGrid (int row, int col, String cmd, char[][] grid) {
return true;
}
public static void swap (int row, int col, String cmd, char[][] grid){
}
public static boolean updateGrid (char[][] grid, char[] options) {
return false;
}
}
'