Skip to content

Commit e579632

Browse files
committed
๐Ÿš€[feat] ์ž๋ฐ” - ์ด์ฐจ์›๋ฐฐ์—ด
1 parent ff28b91 commit e579632

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package practiceJAVA;
2+
3+
public class MultidimensionalArray {
4+
public static void main(String[] args) {
5+
// ๋ฐฐ์—ด ์ƒ์„ฑ
6+
int[][] scores = {
7+
{90,90,96},
8+
{80,81}
9+
};
10+
11+
// ๋ฐฐ์—ด์˜ ๊ธธ์ด
12+
System.out.printf("1์ฐจ์› ๋ฐฐ์—ด์˜ ๊ธธ์ด๋Š” %d์ž…๋‹ˆ๋‹ค.\n", scores.length); // 2
13+
System.out.printf("2์ฐจ์› ๋ฐฐ์—ด์˜ ์ฒซ๋ฒˆ์งธ ๊ธธ์ด๋Š” %d์ž…๋‹ˆ๋‹ค.\n", scores[0].length); // 3
14+
15+
// ํŠน์ • ์›์†Œ ์ถœ๋ ฅ
16+
System.out.printf("์ฒซ๋ฒˆ์งธ ๋ฐ˜์˜ ๋‘๋ฒˆ์งธ ํ•™์ƒ์˜ ์ ์ˆ˜๋Š”: %d์ž…๋‹ˆ๋‹ค. \n", scores[0][1]);
17+
18+
// ํ™œ์šฉ1. ํ‰๊ท  ๊ตฌํ•˜๊ธฐ
19+
int averageScore = 0;
20+
int sum = 0;
21+
int count = 0;
22+
for (int i=0; i<scores.length; i++) {
23+
for(int j=0; j < scores[i].length; j++) {
24+
sum += scores[i][j];
25+
count += 1;
26+
}
27+
}
28+
System.out.printf("์ด ํ‰๊ท ์€ %f์  ์ž…๋‹ˆ๋‹ค.\n", sum/(double)count);
29+
30+
}
31+
32+
}

0 commit comments

Comments
ย (0)