1, create a one-dimensional, two-dimensional array, there are two methods, respectively:
1) Declare first and then use the new operator for memory allocation
One-dimensional: int arr[]; Declares an array of type int, each element in the array is of type int int[] arr;
Two-dimensional: int arr[][]; Int[][] arr;
after declaring an array , you cannot immediately access any of its elements , because declaring an array simply gives the array name and the data type of the element, and if you want to actually use the array, allocate memory space for it, When allocating memory space for an array, you must indicate the length of the arrays .
One-dimensional: arr=new int[5];
Two-dimensional: arr=new int[2][4];
2) allocating memory for arrays at the same time as declared
One-dimensional: int month[]=new int[12];
Two-dimensional: int month[][]=new int[2][2];
2. Initialize one-dimensional, two-dimensional arrays
One-dimensional: int arr[]=new int[]{1,2,3}; int arr[]={1,2,3};
Two-dimensional: int arr[][]=new int[][]{{1,2},{3,4}}; int arr[][]={{1,2},{3,4}}; Explanation: A[0][0]=1, a[0][1]=2, a[1][0]=3, a[1][1]=4
6th array Creating arrays and initializing arrays