-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMultyDimEx.java
More file actions
34 lines (27 loc) · 880 Bytes
/
Copy pathArrayMultyDimEx.java
File metadata and controls
34 lines (27 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.javaex.reftype;
public class ArrayMultyDimEx {
public static void main(String[] args) {
// 2차원 배열의 선언
int[][] twoDimen = new int[5][10];
int table[][] = {
{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
{2, 3, 4, 5, 6, 7, 8, 9, 0, 1},
{3, 4, 5, 6, 7, 8, 9, 0, 1, 2},
{4, 5, 6, 7, 8, 9, 0, 1, 2, 3},
{5, 6, 7, 8, 9, 0, 1, 2, 3, 4}
};
System.out.println("table.length:" + table.length);
// table[0] ~ table[table.length - 1]
System.out.println("table[0].length:" + table[0].length);
int sum = 0;
for (int row = 0; row < table.length; row++) {
// table[row], table[row].length
for (int col =0; col < table[row].length; col++) {
System.out.print(table[row][col] + "\t");
sum += table[row][col];
}
System.out.println();
}
System.out.println("Sum = " + sum);
}
}