以下のコードを使用して配列を作成して配列に挿入しましたが、配列の印刷に関してはArrays.toString()
関数を使用しているときに期待した結果が得られません。配列の要素をArrays.toString()で出力する
よりもむしろ
newArray: [2, 4, 6]
newArray: [8, 10, 12]
etc..
を印刷するには、コード
newArray: [[[email protected], [[email protected], [[email protected], [[email protected]]
newArray: [[[email protected], [[email protected], [[email protected], [[email protected]]
etc..
を出力します。
public static void main(String[] args) {
int[][] newArray = new int[4][3];
int number = 2;
for (int rowCounter = 0; rowCounter < newArray.length; rowCounter++) {
for (int colCounter = 0; colCounter < newArray[rowCounter].length; colCounter++) {
newArray[rowCounter][colCounter] = number;
number += 2;
}
System.out.println("newArray: " + Arrays.toString(newArray));
}
}
これですべてのヘルプははるかに高く評価されるだろう。
ここで結果は配列内の配列のアドレスです。実際の値ではありません –