不規則な配列をサポートするために列のサイズを動的に変更するにはどうすればよいですか?Java:2D配列の動的なサイズの列
int[][] x;
x = new int[3][] //makes 3 rows
col = 1;
for(int i = 0; i < x.length; i++){
x = new int[i][col]
col++; }
上記のコードで各桁の長さが割り当てられますか?
ご協力いただきありがとうございます。
不規則な配列をサポートするために列のサイズを動的に変更するにはどうすればよいですか?Java:2D配列の動的なサイズの列
int[][] x;
x = new int[3][] //makes 3 rows
col = 1;
for(int i = 0; i < x.length; i++){
x = new int[i][col]
col++; }
上記のコードで各桁の長さが割り当てられますか?
ご協力いただきありがとうございます。
x
を再割り当てしているため、それぞれのループ全体が2Dループ全体を作成していますが、間違っています。
あなたがループ内で実行する必要があります。
2Dアレイでx[i] = new int[col];
// create the single reference
int[][] x;
// create the array of references
x = new int[3][] //makes 3 rows
int col = 1;
for(int i = 0; i < x.length; i++){
// this create the second level of arrays // answer
x[i] = new int[col];
col++;
}
より。 - https://www.willamette.edu/~gorr/classes/cs231/lectures/chapter9/arrays2d.htm
これはまさに私がやっていることです!シンタックスをありがとうございました! – Qbert