int[][] multD = new int[5][];
multD[0] = new int[10];
인터넷에서 5x10배열 만드는 소스라고 이런 소스를 봤는데 문법에러가 납니다. Why is that?
java multidimensional-array
int[][] multi = new int[5][10];
Do it like this.
Or
int[][] multi = new int[5][];
multi[0] = new int[10];
multi[1] = new int[10];
multi[2] = new int[10];
multi[3] = new int[10];
multi[4] = new int[10];
You can also do this. Also, if you want to initialize all the elements,
int[][] multi = new int[][]{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
You can do this.
© 2024 OneMinuteCode. All rights reserved.