我制作了一个多维数组(identifier [] []),我将其分配给一个变量'x',以识别1-9整数的单元格,所以我可以更舒适地使用它们。但是,如何将'x'值分配给cell []数组,因此我可以将它传递到我的主函数中并在for循环之后(“单元格号为:”)打印出来?如果我需要更改我的printTable函数,那么如何更改它,所以返回值将是一个数组? (我试图做一个井字棋程序)如何将整数值分配到数组中并将它们传递给另一个函数?
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
printTable();
System.out.print("Cell numbers are: ");
for(int i = 0; i < 9; i++) {
System.out.print("");
if (i != 8) {
System.out.print(", ");
} else {
System.out.print(".");
}
}
input.close();
} // End of main.
public static void printTable() {
int rows = 3;
int columns = 3;
int[][] identifier = new int[rows][columns];
int x = 1;
int[] cell = new int[9];
for(int i = 0; i < rows; i++) {
for(int j = 0; j < columns; j++) {
identifier[i][j] = x;
if (i == 0 && j == 0) {
System.out.println("+---+---+---+");
}
System.out.print("| " + x + " ");
cell[x];
x++;
if (j == columns - 1) {
System.out.print("|");
}
}
System.out.println("");
System.out.println("+---+---+---+");
}
System.out.println("Enter a number between (1-9): ");
} // End of printTable.