変数 'x' に割り当てた多次元配列 (identifier[][]) を作成し、1 ~ 9 の整数でセルを識別したので、より快適に作業できました。しかし、'x' 値を cell[] 配列に割り当てるにはどうすればよいので、それをメイン関数に渡し、for ループの後に出力できます ("Cell numbers are: ")? また、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.