0
私はn * mで2次元配列を回転させるための解決策について昨日尋ねました。 私はこのリンクを回答として受け取ります:How do you rotate a two dimensional array?java.lang.ArrayIndexOutOfBoundsException:90 - 回転するn * m配列
私はベストを尽くしました。私はうまく動作します。そして、それはn * n配列のために機能しますが、nとmが異なる場合、私はIndexOutOfBoundsエラーを受け取り、なぜアイデアがないのでしょうか。ここで
は私のコードです:
public void rot90DegRight(){
//get Matrix
this.Matrix = getMatrix();
int rows = Matrix.length;
int cols = Matrix[0].length;
// create a mirror of current matrix
RGBColor[][] mirror = getMatrix();
// create a new matrix
for (int i = 0; i < rows; i++){
for (int j = 0; j < cols; j++){
Matrix[j][rows - i - 1] = mirror[i][j];
}
}
// replace cols count with rows count
int tmp = rows;
rows = cols;
cols = tmp;
}
を助けるため、あなたにたくさんありがとうございました。
よくリンクされている質問では、固定された行と列を意味する_多次元array_の解決策が明確に示されています。彼らは** _ _できません_。 –