1.
class ObjArrayEx1 {
public static void main(String[] args) {
int [][]test = new int[2][3];
test[0][0] = 100;
test[0][1] = 200;
test[0][2] = 300;
test[1][0] = 500;
test[1][1] = 600;
test[1][2] = 700;
int [][]a = {{100, 200, 300}, {400, 500, 600}};
for(int i = 0;i < test.length;i++)
for(int j = 0;j < test[i].length;j++)
System.out.println("test["+ i +"]["+ j +"] = "+ test[i][j]);
}
}
* 가변배열
2.
class ObjArrayEx1 {
public static void main(String[] args) {
int [][]test = new int[2][];
test[0] = new int[3];
test[1] = new int[2];
test[0][0] = 100;
test[0][1] = 200;
test[0][2] = 300;
test[1][0] = 500;
test[1][1] = 600;
int [][]a = {{10, 20, 30}, {50, 60}};
}
}
3.
class ObjArrayEx1 {
public static void main(String[] args) {
char []abc = {'A', 'B', 'C', 'D'};
char []number = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
System.arraycopy(abc, 0, number, 0, abc.length);
System.out.println(new String(number));
System.arraycopy(abc, 0, number, 6, 3);
System.out.println(new String(number));
}
}
* abc 배열을 number 배열에 0번째부터 abc.length만큼 붙여넣겠다
'Programming > Java' 카테고리의 다른 글
변수 (0) | 2011.01.16 |
---|---|
클래스와 객체 (0) | 2011.01.13 |
문자열 배열 (0) | 2011.01.10 |
버블정렬 (0) | 2011.01.10 |
Math.random (0) | 2011.01.10 |