私はそれを説明しようとした
(私は、コメントを使用したコードを参照してください)
public static void main(String[] args) {
int[][] magic = new int[7][5]; //<<Create a new Bidimentional Array
odd(magic);
}
public static void odd(int[][] magic) {
int N = magic.length; //it will take the length in position 0 from array well the 7 [7][5] so if i use [2][10] it will 2 the length DON'T TRY USE [0][n] or u'll get an error
int row = N - 1; // 7 - 1 = 6 (or your value used [VALUE_TAKEN][n])
int col = N/2; // 7/2 = 3 (or your value used [VALUE_TAKEN][n])
magic[row][col] = 1; //Here you get an error if you used [0][n], BUT if you used [7][5] well it will say magic[6][3] = 1
for (int i = 2; i <= N * N; i++) { //for i=2 ; i < 14; i ++
if (magic[(row + 1) % N][(col + 1) % N] == 0) { // (col + 1) % N] = 0,(col + 1) % N] = 4, so if magic[0,4] == 0 enter
row = (row + 1) % N; //SO IF IT'S TRUE YOU ENTER
col = (col + 1) % N;
} else {
row = (row - 1 + N) % N; //it was not true
}
magic[row][col] = i; //no matter what you will be here
}
}
[] [] '' 0 'に等しい魔法 '内の値の1つが' if'文はチェックしています。 – David
'if'ステートメントのどの部分を理解できませんか? 'row + 1'(演算子の追加)? 'xxx%N'(モジュラス演算子)? 'magic [xxx]'(配列インデックス参照)? 'xxx == 0'(等価演算子)ですか? ---しかし、普通の英語では、現在のセルの右下にあるセルが空であるかどうかを確認し、必要に応じて折り返します。 – Andreas
ありがとうございます。私は各オペレータの機能を理解しましたが、現在のセルの右下にあるセルが空であるかどうかを確認します。コードのどの部分がこれを行っていますか...理解できませんでした – Madhura