Since there are various declaration & initialization methods, I have identified the ones that do not cause a compile error.
python
public class A {
public static void main(String[] args) {
/*One-dimensional array*/
int[] ary = new int[3];
int ary2[] = new int[3];
int []ary3 = new int[3];
int ary4[];
ary4 = new int[3];
// int ary4[];
// ary4 = {1, 2, 3}; #=>Compile error
int ary5[] = {1, 2, 3};
int ary6[] = new int[] {1, 2, 3}; //Specify type and initialize
// int ary7[] = new int[3] {1, 2, 3}; #=>Compile error
/*Two-dimensional array*/
int[][] ary8 = new int[3][3];
int ary9[][] = new int[3][3];
int []ary10[] = new int[3][3];
int[] ary11[] = new int[3][3];
int [][]ary12 = new int[3][3];
int ary13[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
}
Recommended Posts