배열 선언

package ch01;

//기본 자료형 배열
public class ArrayExam {
    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        for(int i = 0; i < a.length; i++){
            System.out.println("a[" + i + "] = " + a[i]);
        }
    }
}
package ch01;

public class ArrayExam2 {
    public static void main(String[] args) {
        String[] str = new String[3];
        str[0] = "Hello ";
        str[1] = "java ";
        str[2] = "world ";

        for(String s : str){ // itar (단축키)
            System.out.print(s);
        }
    }
}
package ch01;

public class ArrayExam3 {
    public static void main(String[] args) {
        int[] a;
        int[] b;
        int[] c = {31, 32, 33};
        a = new int [4];
        b = new int[]{21, 22, 23, 24};
        c = b; // 값이 바뀌지 않고 가르키는 주소값이 바뀜 (c와 b의 주고 같아짐)
        System.out.println(a.length + " " + b.length + " " + c.length);
    }
}