1. 2์ฐจ์ ๋ฐฐ์ด์ ์ ์ธ๊ณผ ์ธ๋ฑ์ค
ex) 4ํ 3์ด์ ๋ฐ์ดํฐ
int[][] data = new int[4][3];
๋ฐฐ์ด์์์ ํ์ ์ธ int์ ๊ธฐ๋ณธ ๊ฐ 0์ผ๋ก ์ด๊ธฐํ๋๋ค.
2์ฐจ์ ๋ฐฐ์ด์ index
score[0][0] ~ score[3][2]๊น์ง ์ด 4x3(12)๊ฐ์ ๊ณต๊ฐ์ด ๋ง๋ จ๋๋ค.
2. 2์ฐจ์ ๋ฐฐ์ด์ ์ด๊ธฐํ
int[][] arr = new int[][]{{1, 2, 3}, {4, 5, 6}};
int[][] arr = {{1, 2, 3}, {4, 5, 6}};
int[][] arr = {
{1, 2, 3},
{4, 5, 6}
}
์์๋ก ์ดํด๋ณด๊ธฐ
int[][] score = {
{100, 100, 100},
{20, 20, 20},
{30, 30, 30},
{40, 40, 40},
{50, 50, 50}
};
for (int i = 0; i < score.length; i++) {
for (int j = 0; j < score[i].length; j++) {
System.out.print(score[i][j] + " ");
}
System.out.println();
}
2์ฐจ์ ๋ฐฐ์ด = 1์ฐจ์ ๋ฐฐ์ด์ ๋ฐฐ์ด = ๋ฐฐ์ด์ ๋ฐฐ์ด
ํฅ์๋ for๋ฌธ์ผ๋ก 2์ฐจ์ ๋ฐฐ์ด ์ฝ๊ธฐ
int[][] score = {
{100, 100, 100},
{20, 20, 20},
{30, 30, 30},
{40, 40, 40},
{50, 50, 50}
};
for (int[] tmp : score) {
for (int i : tmp) {
System.out.print(i + " ");
}
System.out.println();
}
3. ๊ฐ๋ณ ๋ฐฐ์ด
int[][] score = new int[5][]; // ๋ ๋ฒ์งธ ์ฐจ์์ ๊ธธ์ด ์ง์ x
score[0] = new int[4];
score[1] = new int[3];
score[2] = new int[2];
score[3] = new int[2];
score[4] = new int[3];
2์ฐจ์ ๊ฐ๋ณ ๋ฐฐ์ด ์์ฑ & ์ด๊ธฐํ
int[][] score = {
{100, 100, 100, 100},
{20, 20, 20},
{30, 30},
{40, 40},
{50, 50, 50}
}
Reference
์๋ฐ์ ์ ์ - ๋จ๊ถ ์ฑ
'๐ Book > ์๋ฐ์ ์ ์' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
6-3์ฅ ๋ณ์์ ๋ฉ์๋ ไธ (3.1 ~ 3.6) (0) | 2023.04.04 |
---|---|
6-2์ฅ ํด๋์ค์ ๊ฐ์ฒด (0) | 2023.03.29 |
5-2์ฅ String๋ฐฐ์ด (0) | 2023.03.29 |
5-1์ฅ ๋ฐฐ์ด (0) | 2023.03.29 |
4-2์ฅ ๋ฐ๋ณต๋ฌธ (0) | 2023.03.29 |
๋๊ธ