1. 2์ฐจ์ ๋ฐฐ์ด ์ํ (๋ชจ๋ ํ์ ๊ธธ์ด๊ฐ ๊ฐ์ 2 ์ฐจ์ ๋ฐฐ์ด)
String[][] seats = new String[][]{
{"A1", "A2", "A3", "A4", "A5"},
{"B1", "B2", "B3", "B4", "B5"},
{"C1", "C2", "C3", "C4", "C5"}
};
for (int i = 0; i < 3; i++) { // ์ธ๋ก
for (int j = 0; j < 5; j++) { // ๊ฐ๋ก
System.out.print(seats[i][j] + " ");
}
System.out.println();
}
// ํ๋์ฝ๋ฉ ํผํ๊ณ ์ถ์ผ๋ฉด 3๊ณผ 5๋ฅผ ๊ฐ๊ฐ seats.length, seats[i].length๋ก ๋ฐ๊พธ๋ฉด ๋๋ค.
2. 2์ฐจ์ ๋ฐฐ์ด ์ํ (ํ ๋ง๋ค ๊ธธ์ด๊ฐ ๋ค๋ฅธ 2์ฐจ์ ๋ฐฐ์ด)
String[][] seats2 = {
{"A1", "A2", "A3"},
{"B1", "B2", "B3", "B4"},
{"C1", "C2", "C3", "C4", "C5"}
};
//seats2[2] -> 2์ฐจ์ ๋ฐฐ์ด ์์ 3๋ฒ์งธ ํ์ธ 1์ฐจ์ ๋ฐฐ์ด์ ๊ฐ๋ฆฌํด.
//seat2.length -> 2์ฐจ์ ๋ฐฐ์ด ์์ 1์ฐจ์ ๋ฐฐ์ด์ ๊ฐฏ์
for (int i = 0; i < seats2.length; i++) { // ์ธ๋ก
for (int j = 0; j < seats2[i].length; j++) { // ๊ฐ๋ก
System.out.print(seats2[i][j] + " ");
}
System.out.println();
}
3. ๋ฐฐ์ด ์๋ ์ด๊ธฐํ (๊ฐ์ด ์์ฒญ ๋ง์ ๋ ์ ์ฉ)
// ๋ฐฐ์ด ์๋ ์ด๊ธฐํ
// ์ธ๋กํฌ๊ธฐ 10 x ๊ฐ๋ก ํฌ๊ธฐ 15์ ํด๋นํ๋ ์ํ๊ด ๊ฒ์
String[][] seats3 = new String[10][15];
String[] eng = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
for (int i = 0; i < seats3.length; i++) {
// seats3[i].length == ํด๋น ํ์ ๊ฐ๋ก ๊ธธ์ด
for (int j = 0; j < seats3[i].length; j++) {
// ๊ฐ ์๋ฆฌ์ ๊ฐ ์ด๊ธฐํ (j + 1์ ๊ดํธ ์ณ์ค์ผ int ๊ณ์ฐ์์ ์ธ์, ๊ดํธ ์์ผ๋ฉด String ๊ณ์ฐ์ธ ์ค ์๋ค.)
// j๋ 0๋ถํฐ ์์์ด๋๊น +1
seats3[i][j] = eng[i] + (j + 1);
}
}
// ํ ๊ตฌ๋งค
seats3[7][8] = "__"; //H9
seats3[7][9] = "__ "; //H10
//์ํ๊ด ์ข์ ๋ฒํธ ํ์ธ
for (int i = 0; i < seats3.length; i++) { // ์ธ๋ก
for (int j = 0; j < seats3[i].length; j++) { // ๊ฐ๋ก
System.out.print(seats3[i][j] + " ");
}
System.out.println();
}
0