๊ด€๋ฆฌ ๋ฉ”๋‰ด

JiYoung Dev ๐Ÿ–ฅ

[์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] ์ด์ฐจ์›๋ฐฐ์—ด, ๋น„์ •๋ฐฉํ˜•๋ฐฐ์—ด (2023.04.03) ๋ณธ๋ฌธ

full stack/JAVA

[์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] ์ด์ฐจ์›๋ฐฐ์—ด, ๋น„์ •๋ฐฉํ˜•๋ฐฐ์—ด (2023.04.03)

Shinjio 2023. 4. 3. 17:13

๐Ÿ”Ž ์ด์ฐจ์›๋ฐฐ์—ด

๋ฐฐ์—ด์˜ ์š”์†Œ๋กœ 1์ฐจ์› ๋ฐฐ์—ด์„ ๊ฐ€์ง€๋Š” ๋ฐฐ์—ด

 

๐Ÿ“– ์ด์ฐจ์› ๋ฐฐ์—ด์˜ ๊ตฌ์กฐ

 

1์ฐจ์› ๋ฐฐ์—ด๋“ค์ด ์žˆ๊ณ , ์ด๋“ค์˜ ๋ ˆํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜๋“ค์„ ์ €์žฅํ•˜๋Š” ๋ฐฐ์—ด์ด ์žˆ๊ณ , ์ด ๋ฐฐ์—ด์˜ ๋ ˆํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜๊ฐ€ ์žˆ์Œ

๊ฐ๊ฐ์˜ ๋ ˆํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜๋“ค๋„ ํ•˜๋‚˜์˜ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์— ์ €์žฅํ•˜๊ณ  ๋ ˆํผ๋Ÿฐ์Šค ๋ฐฐ์—ด์— ๋Œ€ํ•œ ๋ ˆํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜ ์ƒ์„ฑ ํ•„์š”

(๋ ˆํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฐฐ์—ด → ๋ ˆํผ๋Ÿฐ์Šค ๋ฐฐ์—ด)

 

๐Ÿ“– ์ด์ฐจ์›๋ฐฐ์—ด์˜ ์ƒ์„ฑ

int[][] seat = new int[5][3];      ----->  5ํ–‰ 3์—ด์˜ ํ–‰๋ ฌ ์ƒ์„ฑ
์ž๋ฃŒํ˜•[][] ๋ ˆํผ๋Ÿฐ์Šค๋ณ€์ˆ˜๋ช…  =  new ์ž๋ฃŒํ˜•[๋ ˆํผ๋Ÿฐ์Šค ๋ฐฐ์—ด์˜ ๊ธธ์ด][์ผ์ฐจ์› ๋ฐฐ์—ด์˜ ๊ธธ์ด]

 

์ด์ฐจ์› ๋ฐฐ์—ด์—์„œ ์ผ์ฐจ์› ๋ฐฐ์—ด์˜ ๊ธธ์ด๋Š” ๋ชจ๋‘ ๊ฐ™๋‹ค

 

๐Ÿ“– ์ด์ฐจ์›๋ฐฐ์—ด์˜ ์ดˆ๊ธฐํ™”

int[][] intArray = {{0,1,2}, {3,4,5},{6,7,8}};

 

๐Ÿ“– ๋ฐฐ์—ด์— ๊ฐ’ ๋„ฃ๊ธฐ

seat[0][0] = 1;
seat[3][2] = 20;

 

 

์ด์ฐจ์›๋ฐฐ์—ด ์‹ค์Šต1

 

 

์ด์ฐจ์›๋ฐฐ์—ด ์‹ค์Šต2

 

 

โ–ผ ์Œค ํ’€์ด โ–ผ 

์ฐจ์ด์  : for ์กฐ๊ฑด๋ฌธ์˜ ๊ธฐ๋ณธ ๊ตฌ์กฐ๋Š” ๋ฐ”๊พธ์ง€ ์•Š๊ณ , ์‹คํ–‰๋ฌธ๋งŒ ์•ฝ๊ฐ„ ๋ณ€๊ฒฝํ•ด์„œ ์ž‘์„ฑํ–ˆ์Œ

 

 

 

๐Ÿ”Ž๋น„์ •๋ฐฉํ˜•๋ฐฐ์—ด

 

int[][] seat = new int[5][];
๊ฐ๊ฐ์˜ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋ฅผ ๋”ฐ๋กœ ์ •ํ•ด์ค˜์•ผ ํ•จ

seat[0] = new int[1];
seat[1] = new int[2];
seat[2] = new int[3];
seat[3] = new int[1];
seat[4] = new int[3];

 

์ •๋ฐฉํ˜•๋ฐฐ์—ด ์‹ค์Šต1